【发布时间】:2015-11-17 16:26:18
【问题描述】:
嗨,我需要从另一个名为 parent.php 的 php 中执行文件夹 child 上的 php child.php,并在 parent.php 处获取 child.php 的输出。我有下面的代码,但不能工作,因为 child.php 应该从文件夹 child 本身执行。
如何解决这个问题,比如将目录更改为child 并在那里执行 php 并获取输出。
function execute($filename){
ob_start();
include $filename;
$output = ob_get_contents();
ob_end_clean();
return $output;
}
【问题讨论】:
-
您可以在运行此
execute()函数之前将chdir()转换为child/,然后再改回(如有必要)。 php.net/manual/en/function.chdir.php 没有更多关于child.php中实际内容的详细信息,没有更多可推测的内容。 -
W.T.F? û_O 你能否更详细地了解
should executed from the folder -
@Blag
should executed from the folder因为在child php我使用相对路径来获取一些文件内容,目前我无法访问更改child.php,我只能编辑parent.php
标签: php