Create PHP File - C

Create PHP File

Snippet Code

Rate this page :
  [ 0 votes]

#include <stdio.h> int main() { int filehandle; char filename[20]; char countername[20]; int count; FILE *fp; printf(<q>Please enter the name of the file you wish to createn</q>); printf(</q>in the format myfile.php : n</q>); gets(filename); printf(<q>Now enter a name for the counter file.n</q>); gets(countername); printf(<q>Please enter the starting count.n</q>); scanf(<q>%d</q>,ampcount); /*create counterfile with the starting count*/ filehandle = creat(countername,S_IREAD|S_IWRITE); if(fp = fopen(countername,<q>a</q>)) { fprintf(fp,<q>%d</q>,count); fclose(fp); } else printf(<q>cannot open %s </q>,countername); /*create php file*/ filehandle = creat(filename,S_IREAD|S_IWRITE); /*create counter in php file*/ if(fp = fopen(filename,<q>w </q>)) { fprintf(fp,<q><?phpn</q>); fprintf(fp,<q>$counterFile = <q>%s</q>;n</q>,countername); fprintf(fp,<q>$line = file($counterFile);n</q>); fprintf(fp,<q>$line[0] ;n</q>); fprintf(fp,<q>$fp = fopen($counterFile ,<q>w</q>);n</q>); fprintf(fp,<q>fputs($fp, <q>$line[0]</q>);n</q>); fprintf(fp,<q>fclose($fp);n</q>); fprintf(fp,<q>echo $line[0];n</q>); fprintf(fp,<q>?>n</q>); fclose(fp); } else printf(<q>cannot create %s</q>,filename); return 0; } }


Ask Questions

Ask Question