PHP找不到tmp目录 [英] PHP Can't find tmp directory

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

问题描述

我有,在tmp目录下创建文件,如 TMPFILE()的tempnam()。他们似乎都未能写入TMP和返回false。 upload_tmp_dir 在PHP INI和文件上传设置正常工作。

I am having problems with functions that create files in the tmp directory such as tmpfile() and tempnam(). They all seem to fail to write to tmp and return false. upload_tmp_dir is set in php ini and file uploads work fine.

在调试这个错误我发现, sys_get_temp_dir()获取可惜这不是我的PHP版本(5.1.6)支持的tmp目录的位置。我也看到,使用下面的方法替换 sys_get_temp_dir的功能()

When debugging this error I found that sys_get_temp_dir() gets the location of the tmp directory unfortunately it's not supported in my PHP version (5.1.6). I also saw that using the following method replaces the functionality of sys_get_temp_dir():

if ( !function_exists('sys_get_temp_dir')) {
  function sys_get_temp_dir() {
    if (!empty($_ENV['TMP'])) { return realpath($_ENV['TMP']); }
    if (!empty($_ENV['TMPDIR'])) { return realpath( $_ENV['TMPDIR']); }
    if (!empty($_ENV['TEMP'])) { return realpath( $_ENV['TEMP']); }
    $tempfile=tempnam(__FILE__,'');
    if (file_exists($tempfile)) {
      unlink($tempfile);
      return realpath(dirname($tempfile));
    }
    return null;
  }
}

但是,到$ _ENV阵列中的tmp目录和的tempnam()没有提及正如我前面提到失败。

But there is no reference to a tmp directory in the $_ENV array and tempnam() fails as I mentioned before.

另外的open_basedir没有设置,我听说可能会导致类似的问题。

Also open_basedir is not set which I've heard can cause similar problems

我怎样才能找出的tmp目录是否它甚至还成立?结果
这是一个Apache服务器的配置问题还是PHP的?

How can I find out where the tmp directory is or whether it is even set?
Is this a apache server configuration issue or a PHP one?

感谢您的帮助。

推荐答案

TMP,TEMP(也许TMPDIR)是在Windows上才有效,通常指向 C:\\ WINDOWS \\ TEMP 。在Linux默认临时位置是 / tmp目录。要解决这个(与作品的tempnam()功能),你可以在你的网站空间中某个位置创建一个临时文件夹,指定适当的访问权限,并通过这个作为第一个参数上面的函数

TMP, TEMP (and maybe TMPDIR) are valid on Windows only and usually pointing to C:\Windows\TEMP. On Linux default temp location is /tmp. To workaround this (works with tempnam() function) you can create a temp folder somewhere within your website space, specify appropriate access permissions and pass this as first parameter to the above function.

不是一个很好的解决方案,但有总比没有好。

Not a great solution but better than nothing.

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

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