PHP 后台脚本无法访问上传的临时文件



我有一个PHP脚本,它接收上传并通过shell_exec()将上传的处理推迟到后台脚本。

但是后台脚本似乎无法访问上传的临时文件。

接收器脚本

$file_loc = $_FILES['file']['tmp_name'];
echo $file_loc.' exists = '.file_exists($file_loc);
shell_exec('php background.php -i='.$file_loc.' >report.txt &');

此输出

{文件路径}存在=1

Background.php

$args = getopt('i:');
$file_loc = $args['i'];
echo $file_loc.' exists = '.file_exists($file_loc);

在result.txt中,我得到

{文件路径}存在=

即不存在我需要做些什么才能允许后台脚本访问tmp文件位置

您应该将上传的文件移动到一个新的目的地来处理该文件。

$destination = "FOLDER_NAME/".$_FILES['file']['tmp_name'];
$file_loc = $_FILES['file']['tmp_name'];
move_uploaded_file ( $file_loc, $destination )
echo $destination.' exists = '.file_exists($destination);
shell_exec('php background.php -i='.$destination.' >report.txt &');

最新更新