0

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

<?php


$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/");

$start="";

$Fnm = "./include.php";

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

fwrite($inF,$start."\n");



    $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"));

                        fclose($fh);



                    }



                }

                closedir($folder2);

                closedir($folder3);
                closedir($folder4);

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

            fwrite($inF,$result);

           }

    }

    fwrite($inF,"");

    closedir($folder);



fclose($inF);

?>
2
Contributors
5
Replies
7
Views
5 Years
Discussion Span
Last Post by ska_defender
0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.