我有一个php脚本,它位于一个文件夹中我想在每个文件夹中运行相同的脚本,而不是手动上传每个文件中的php文件
例如,我有mysite.com/folder/script.php
和文件夹有不同的子文件夹
所以我想创建一个php文件,在每个文件夹/子文件夹中执行这个script.php,而无需手动上传每个文件夹中的script.php
有办法吗?
更新php代码
$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);
假设您使用的是Apache,您可以通过创建一个htaccess
文件来使用mod_rewrite,该文件如下所示:
RewriteEngine on
RewriteBase /folder/
RewriteRule ^.+/script.php$ script.php
并将其上传到您的服务器。这会打开RewriteEngine
,将基本目录设置为您选择的文件夹,然后每当在子目录中请求script.php
时,它都会返回/folder/script.php
在子文件夹的页面上,包括以下代码:
require_once dirname(__FILE__) . "/folder/script.php";
这就是你的意思吗?