我有一个上传文件的脚本。然后,它创建一个新文件夹,并将上载的文件和另一个脚本一起移动到该文件夹。
移动文件后,我需要运行位于新文件夹中的第二个脚本。但我需要第二个脚本使用它的路径,而不是调用/执行它的路径。(上传脚本)
这就是我尝试从上传脚本执行脚本的方式。
exec("php-cli uploads/".$dirname."/".$file_name."/generate_thumbs.php");
我有错误报告,但没有生成任何内容。有什么想法吗?
如果要更改工作目录,请在exec()
之前使用chdir()
。您可以传递绝对或相对目录名。要从PHP执行PHP,可以使用include
而不是exec()
。
将您的上传脚本编辑为:
<?php
// ... upload the file ...
// ,,open'' the target directory
chdir("uploads/$dirname/$file_name/");
// start the thumbs script
// this filename is relative to "uploads/$dirname/$file_name/"
include "generate_thumbs.php";
?>
您应该在第二个脚本中使用脚本所在位置的路径。
如答案所示:获取当前脚本的绝对路径
从那里你可以编写你的脚本,让它在哪里操作,只要你能解决它在哪里。