shell_exec不会从浏览器请求中执行



用户通过POST提交数据后,我会显示一个临时页面,并在后台使用shell_exec进行处理,至少这就是我要做的。

这是我的页面设置:

C: \laragon\www\index.php

<?php
try {
shell_exec("php " . __DIR__ . "/test.php");
} catch(Exception $e) {
echo "Exception: " . $e;
}
?>

C: \laragon\www\test.php

<?php
$myfile = fopen(__DIR__ . "/testfile.txt", "w");
echo "test";
?>

如果我转到localhost或localhost/index.php,则第二个脚本不会运行。然而,当我尝试从cmd调用这两个脚本时,它可以同时使用这两个。

php C:laragonwwwindex.php
php C:laragonwwwtest.php

它们都工作并创建一个名为testfile.txt 的文件

您的Web服务器以特定用户身份运行,并且需要php.exe的路径,因为Web服务器用户没有路径环境变量:

shell_exec("c:pathtophp " . __DIR__ . "/test.php");

最新更新