Reputation: 21
Is there a way I could use php to make root file to look like its also in other folders too.
For example I have index.php in root folder and I want it to be like that when I access index.php then it could also behave as its in all the folders and subfolders too
When I execute index.php then it will also execute in all folders and subfolders too
Please understand my question by the example below
index.php is in root and I have different folders in root as well so when I access the index.php through browser then it will also execute in other folders
http://mysite.com/index.php will also behave as if its in sub folder too
http://mysite.com/folder1/index.php
http://mysite.com/folder2/index.php
http://mysite.com/folder3/index.php
index.php is not in these folders but it must execute in these folders too at the same time
I think its not difficult to understand through above examples.please answer accordingly
Update 2
Here is the index.php code
It scans the folders "files" "images" "txt" "related" and get the files in each folder and then it writes to the includes.php (in root)
$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);
Upvotes: 0
Views: 409
Reputation: 4150
If you need to cycle through the directories and see if each of those directories contains one of the directories listed in the $path
array you could use something like:
function readDirs()
{
$path=array('images','etc...');
$dirHandle = opendir('./');
while($file = readdir($dirHandle))
{
if(is_dir($file) && $file != '.' && $file != '..')
{
$dirHandle2 = opendir($file);
while($file2 = readdir($dirHandle2))
{
if(in_array($file2,$path))
{
// do what you need to do
}
}
}
}
}
readDirs();
That will cycle through all the directories in the root folder and see if they contain a directory listed in the $path
array, if so you can pop your code in the // do what you need to do
statement.
Hope that helps!
Upvotes: 1