PHP tmpfile() 返回 false
我有一个之前可以运行的图像上传脚本。现在它已损坏,我已将问题追溯到一行:
$temp = tmpfile();
// $temp === false
tmpfile() 函数返回 false。我似乎不明白为什么。我在谷歌上搜索这个问题时遇到了困难。
该脚本仅在我的本地测试环境 OSX 10.6.7、运行 MAMP 1.9.5 上损坏。幸运的是,现场网站运行良好。
I've got an image upload script which was previously working. It's now broken, and I've traced the problem down to one line:
$temp = tmpfile();
// $temp === false
The tmpfile() function is returning false. I can't seem to figure out why. I'm having a hard time wading through Google on this one.
The script it only broken on my local test environment, OSX 10.6.7, running MAMP 1.9.5. Fortunately the live site is working fine.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果tmpfile() 无法创建临时文件,则返回
false
。确保您的 tmp 文件夹可写,并尝试检查 sys_get_temp_dir() 函数返回的内容。tmpfile() returns
false
if it is unable to create the temporary file. Make sure your tmp folder is writable and try and check whatsys_get_temp_dir()
function returns.可能是权限问题。
使用 sys_get_temp_dir() 来查看临时文件将在哪里创建,并确保 php 有权在那里写入。
It might be a problem with permissions.
Use
sys_get_temp_dir()
to see where the temp file will be created and make sure php has access to write there.就我而言,它尝试在其中创建文件的文件夹包含一直到 tmpFFFF.tmp 的临时文件。将这些临时文件从文件夹中移走后,它又从 tmp1.tmp 开始。
In my case, the folder it was trying to create the file in had temp files ranging all the way up to tmpFFFF.tmp. After moving those temp files away from the folder, it started back at tmp1.tmp.
首先,启用所有 PHP 警告,看看它是否在告诉您一些信息。
其次,检查您的临时文件夹并确保 PHP 对其具有写入权限。某些“安全模式”限制(基本目录等)可能会阻止访问。
First, enable all PHP warnings to see if it is telling you something.
Second, check your temp folder and make sure PHP has write access to it. It's possible that certain "safe mode" restrictions (base dirs, etc) are preventing access.