Page 1 of 1

Can php create a file

Posted: Tue Jun 29, 2004 4:41 pm
by Calimero
Is there a way that php create a blank .txt file ex. test.php


Could this way this be done -
I make this file
Then in the script I declare its name as a variable
then I add to its name var $var and use ++$var with if or while loop to use it to create several names
then i use copy and rename each time with the name I found above.

Any suggestions and ideas are welcome


AND YEAH, can php Fopen() html source code to seek for something in it ?

Thanks Ahead!

Posted: Tue Jun 29, 2004 4:52 pm
by markl999

Code: Select all

$howmanyfiles = 5;
for($x=0;$x<$howmanyfiles;$x++){
    $fname = 'test'.$x.'.php';
    touch($fname);
}

Thanks, BUT

Posted: Tue Jun 29, 2004 4:57 pm
by Calimero
I realy appreciate the effort, but, I am still a newbie, so little comment on what this does, and what to do with the code to pursue my goals,
THANKS :)

Posted: Tue Jun 29, 2004 5:00 pm
by markl999
oookie..

Code: Select all

$howmanyfiles = 5; //this is how many files you want to create
for($x=0;$x<$howmanyfiles;$x++){ //this is just a loop that loops round 5 times in this case
    //the line below is the name of the file we want to create..
    //in this example it will create test0.php, test1.php, test2.php ..etc..up to test4.php
    $fname = 'test'.$x.'.php';
    //touch is the command that creates the empty file
    //see http://php.net/touch for more info
    touch($fname);
}