Reputation: 81
I have a php script that resides in a single folder I want to run the same script in each folder wihout manually uploading the php file in each file
for example I have mysite.com/folder/script.php
and folder has different subfolders
so I want to create a php file that will execute this script.php in each folder/subfolder without manually uploading the script.php in each folder
Is there a way ?
Update php code
$path = array("./files/","./images/");
$path2= array("http://".$_SERVER['SERVER_NAME'].dirname($_SERVER["PHP_SELF"])."/files/","http://".$ _SERVER['SERVER_NAME'].dirname($_SERVER["PHP_SELF"])."/images/");
$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]);
$imagename ='';
while( $file2 = readdir($folder2) ) {
if (substr($file2,0,strpos($file2,'.')) == substr($file,0,strpos($file,'.'))){
$imagename = $file2;
}
}
closedir($folder2);
$result="{\nlevels: [\n{ file: \"$path2[0]$file\" }\n],\nimage: \"$path2[1]$imagename\",\ntitle: \"$file\"\n},\n";
fwrite($inF,$result);
}
}
fwrite($inF,"");
closedir($folder);
fclose($inF);
Upvotes: 1
Views: 1785
Reputation: 814
Assuming you are using Apache, you could use mod_rewrite by creating a htaccess
file that looks like this:
RewriteEngine on
RewriteBase /folder/
RewriteRule ^.+/script.php$ script.php
And uploading it to your server. This turns the RewriteEngine
on, sets the base directory to your chosen folder, then whenever script.php
is requested in a subdirectory it will return /folder/script.php
Upvotes: 4
Reputation: 3568
On your subfolder's page, include this code:
require_once dirname(__FILE__) . "/folder/script.php";
Is this what you mean?
Upvotes: 2