首页 > 解决方案 > 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

背景.php

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

在 result.txt 我得到

{文件路径} 存在 =

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

标签: phpshellbackgroundupload

解决方案


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

$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 &');

推荐阅读