php - 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 文件位置?
解决方案
您应该将上传的文件移动到新的目的地以处理该文件。
$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 &');
推荐阅读
- javascript - Google Firebase 实时数据库成员名称
- angular - 将 JSON 数组绑定到嵌套表单组
- elasticsearch - Zabbix 5.4,无法将数据发送到 Elastic Search(日期字段)
- ruby-on-rails - mimemagic 安装错误:“在以下位置找不到 MIME 类型数据库...”在 Windows 上
- python - open .ods file inside python package
- python-3.x - Applying frame independence with none linear movement
- html - 如何在屏幕的某个部分放置图像或文本
- kotlin - 我如何将类枚举中的 var 与 fun main 中的 var 进行比较以生成 when 语句
- css - 将可见性设置为可见并使用 :checked 伪类时元素不出现
- c++ - 重载 [] 或 = 运算符以更改链表中的数据