Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在不同的文件夹中运行相同的php脚本_Php_Readfile - Fatal编程技术网

在不同的文件夹中运行相同的php脚本

在不同的文件夹中运行相同的php脚本,php,readfile,Php,Readfile,我有一个驻留在单个文件夹中的php脚本 我想在每个文件夹中运行相同的脚本,而不需要手动上传每个文件中的php文件 比如我有 mysite.com/folder/script.php 和文件夹有不同的子文件夹 因此,我想创建一个php文件,在每个文件夹/子文件夹中执行这个script.php,而不在每个文件夹中手动上传script.php 有办法吗 更新php代码 $path = array("./files/","./images/"); $path2= array("http://".$_S

我有一个驻留在单个文件夹中的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);

在子文件夹的页面上,包括以下代码:

require_once dirname(__FILE__) . "/folder/script.php";

这就是您的意思吗?

在子文件夹的页面上,包含以下代码:

require_once dirname(__FILE__) . "/folder/script.php";

这就是您的意思吗?

假设您正在使用Apache,您可以通过创建一个
htaccess
文件来使用它,该文件如下所示:

RewriteEngine on
RewriteBase /folder/
RewriteRule  ^.+/script.php$ script.php

并将其上载到您的服务器。这将打开
重写引擎
,将基本目录设置为您选择的文件夹,然后每当在子目录中请求
script.php
,它将返回
/folder/script.php

假设您使用的是Apache,您可以通过创建一个
htaccess
文件来使用它,该文件如下所示:

RewriteEngine on
RewriteBase /folder/
RewriteRule  ^.+/script.php$ script.php

并将其上载到您的服务器。这将打开
重写引擎
,将基本目录设置为您选择的文件夹,然后每当在子目录中请求
script.php
,它将返回
/folder/script.php

否“我的子文件夹”中没有页面(仅包含图像)我不想手动编辑子文件夹页面,需要运行脚本扫描文件夹并在每个文件夹中运行scrip.php。您打算怎么做?从
script.php
访问子文件夹上的内容?我已更新帖子,以包含我要运行的php scriot。实际上,脚本扫描文件夹,然后将其附加到include.php文件中,该文件是自动创建的,因此我要为每个文件夹自动创建include.php文件。我的日志中没有页面子文件夹(仅包含图像)我不想手动编辑子文件夹页面需要运行脚本扫描文件夹并在每个文件夹中运行scrip.php您打算怎么做?从
script.php
访问子文件夹上的内容?我已更新帖子,以包含我要运行的php scriot。实际上,脚本扫描文件夹,然后将其附加到include.php文件中,该文件是自动创建的,因此我要为每个文件夹自动创建include.php文件。请查看我的更新了php代码,它在根目录中生成include.php文件。但我想在每个子文件夹中生成该文件,您可能不太清楚。这似乎有点困难,但是如果你坚持使用这种方法,你可以在
htaccess
include.php中用
include.php
替换
script.php
,它不是实际的文件(由script.php自动生成)。实际上,脚本扫描文件夹,然后将其附加到include.php文件中,该文件是自动创建的,因此我想为每个文件夹自动创建include.php文件。我上面更新的代码是针对script.php not include.phpIn的。在这种情况下,您希望在
glob
上运行
foreach
循环。请看我更新的php代码,它在根目录中生成include.php文件。但是我想在每个子文件夹中生成这个文件,你不太清楚。这似乎有点困难,但是如果你坚持使用这种方法,你可以在
htaccess
include.php中用
include.php
替换
script.php
,它不是实际的文件(由script.php自动生成)。实际上,脚本扫描文件夹,然后将其附加到include.php文件中,该文件是自动创建的,因此我想为每个文件夹自动创建include.php文件。我上面更新的代码是针对script.php not include.phpIn的。在这种情况下,您希望在
glob
上运行
foreach
循环。看到这个了吗