I have a problem that I'm sure is a piece of cake for you guys to work out.

I have a small index.php script here which creates a php file (with text appended from the index.php script) each time the page is visited. The problem is that I can only get the files to be created in the same folder as the .php file. I want the file to be generated in each folder and sub folder but can't get it to work.

Or is there a way when I access index.php then this file index.php will run in each folder and subfolder to act as if index.php is in all of these folders(without copying the index.php to each folder)

Here is the code


$path = array("./files/","./images/","./txt/","./related/");

$path2= array("http://".$_SERVER['SERVER_NAME'].dirname($_SERVER["PHP_SELF"])."/files/","http://".$_SERVER['SERVER_NAME'].dirname($_SERVER["PHP_SELF"])."/images/","http://".$_SERVER['SERVER_NAME'].dirname($_SERVER["PHP_SELF"])."/txt/","http://".$_SERVER['SERVER_NAME'].dirname($_SERVER["PHP_SELF"])."/related/");


$Fnm = "./include.php";

$inF = fopen($Fnm,"w");


    $folder = opendir($path[0]);

    while( $file = readdir($folder) ) {

           if (($file != '.')&&($file != '..')&&($file != 'index.htm')) {

                $folder2 = opendir($path[1]);

                $folder3 = opendir($path[2]);
                $folder4 = opendir($path[3]);

                $imagename ='';

                $txtname ='';
                $related ='';

                while( $file2 = readdir($folder2) ) {

                    if (substr($file2,0,strpos($file2,'.')) == substr($file,0,strpos($file,'.'))){

                        $imagename = $file2;


while( $file4 = readdir($folder4) ) {

                    if (substr($file4,0,strpos($file4,'.')) == substr($file,0,strpos($file,'.'))){

                        $related = $file4;



while( $file3 = readdir($folder3) ) {

if (substr($file3,0,strpos($file3,'.')) == substr($file,0,strpos($file,'.'))){

                        $txtname = $file3;

                        $fh = fopen("/home3/socialb8/public_html/mysite.info/player/txt/$txtname", 'r');

                        $theData = fread($fh, filesize("/home3/socialb8/public_html/mysite.info/player/txt/$txtname"));






            $result="{\nlevels: [\n{ file: \"$path2[0]$file\" }\n],\nimage: \"$path2[1]$imagename\",\ntitle: \"$file\",\ndescription: \"$theData\",\n 'related.file':'$path2[3]$related'\n},\n";








When you create a new (sub)folder, you'll have to give write permissions with chmod.

pritaeas I already did it
just want to know how it could write to each folder
at the moment its not
its just writing in the same dir where index.php resides

and are you talking about chmod 777 throguh ftp or in script itself ?

When writing, do you specify the correct path?

Yes the path is correct and its working also for only the main folder