更改PHP临时目录 [英] Changing PHP Temp Directory

查看:253
本文介绍了更改PHP临时目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个媒体转换站点,用户可以在其中上传视频,音频或图像文件,并将其转换为3种流行格式.转换脚本可以正常工作,但是文件上传到的tmp目录存在一些问题.我已经尝试了两种方案,但两种方案都可以,但是都行不通,在我看来,这与权限相关,但是我似乎可以解决问题. 在解决问题时,我现在正在本地工作.

I have a site for media conversion where users can upload video, audio or image files and it is converted in to 3 popular formats. Conversion script works fine but I am having some issues with the tmp directory where the files get uploaded to. I have tried 2 scenarios I am fine with either but neither works and it seems to me to be permissions related but I can seem to fix the problem. I am working locally right now while I work out the kinks.

方案1:

  • 文件已上传到默认的本地tmp目录(C:\ WINDOWS \ tmp)-运行正常
  • 尝试使用已上传的tmp文件运行转换脚本,但该脚本无法正常工作-从命令行运行仍然可以正常运行

方案2:

  • 文件已上载到我已完全控制IIS_IUSRS的目录(用于测试),并且文件不会上载-是的,该目录的拼写正确(我更改了php.ini中的upload_tmp_dir值)

将XMLHttpRequest发送到PHP文件的JavaScript站点以及PHP文件本身所在的站点都是IIS站点,因此我假设脚本以IIS_IUSRS的身份运行.

Both the site the javascript that send the XMLHttpRequest to the PHP file, as well as the site the PHP file itself reside on are IIS sites so I assume the script is being run as IIS_IUSRS.

对于方案1根本不再创建临时文件,无法弄清楚为什么我假设使用权限播放会弄乱某些东西,因为代码没有更改.我已经给IIS_USRS和USERS进行了修改,以尝试使其再次运行,但没有运气:(尽管错误日志仍在写入同一文件夹...很奇怪

Temp file is no longer being created at all for Scenario 1, can't figure out why I am assuming playing with permission messed something up because the code hasn't changed. I've given Modify to IIS_USRS and USERS to try and get it working again but no luck :( although the error log is still writing to the same folder...weird

注意:我发送的$ _FILES变量的"tmp_name"值仍然具有"C:\ WINDOWS \ Temp \'filename'"的值,但是文件不存在

NOTE: The "tmp_name" value of the $_FILES variable I am sending still has a value of "C:\WINDOWS\Temp\'filename'" but the file is not there

另一个新开发,它似乎不是权限问题,因为我可以通过$ temp_file = tempnam(sys_get_temp_dir(),'Test')创建一个临时文件.但是它显然不包含上传的数据,因此不能解决我的问题

Another new development, it appears it is NOT a permissions issue because I can create a temp file via $temp_file = tempnam(sys_get_temp_dir(), 'Test'); however it obviously does not contain the uploaded data so it does not solve my problem

推荐答案

这不是要解决的问题,而是更多的解决方法.问题似乎与 $_FILES['file']['tmp_name'];

This is less of a problem solved and more of a workaround. The issue seems to be something with the $_FILES['file']['tmp_name'];

当我回显内容时,它看起来与预期的一样,但是没有文件出现.因此,我没有利用自然发生的过程,而是不得不采取手动方法.我所做的是以下事情:

When I echo the contents it looks as I expect however no file appears. So rather than taking advantage of that process that happens naturally, I have had to take a manual approach. What I have done is the following:

创建一个临时文件

$temp_file = tempnam(ini_get('upload_tmp_dir'), 'php');

然后从$ _POST请求期间创建的临时文件中添加内容. (即使我在目录中查找文件时,即使文件不在$ _FILES变量中,该变量也是如此)

then add the content from the temp file created during the $_POST request. (which some how are in the $_FILES variable even though the file is not when I look in the directory)

file_put_contents($temp_file, file_get_contents($_FILES['file']['tmp_name']));

我有我的临时文件要处理.

the I have my temporary file for processing.

这篇关于更改PHP临时目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆