尽管具有777权限并且没有open_basedir值,但无法使用php写入/tmp [英] Can't write to /tmp with php, despite 777 permissions and no open_basedir value

查看:270
本文介绍了尽管具有777权限并且没有open_basedir值,但无法使用php写入/tmp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用php fopen函数将文件写入我的/tmp目录(在apache服务器上),但是失败:

I'm trying to write a file to my /tmp directory (on an apache server) with the php fopen function, but it fails:

<?php
$handle = fopen("/tmp/test.txt", "x");
if ($handle) 
   echo "Success!";
else 
    print_r(error_get_last());

这将返回错误消息:

无法打开流:没有这样的文件或目录.

failed to open stream: No such file or directory.

/tmp目录的权限设置为drwxrwxrwt,我可以看到Web用户正在向其写入其他文件.奇怪的是,如果我将脚本指向具有权限777的另一个文件夹,它将返回成功.但是我的open_basedir没有任何价值.我有safe_mode=onallow_url_fopen=off,但我认为不应该解释吗?

The /tmp directory has permissions set to drwxrwxrwt and I can see that the web user is writing other files to it. Mysteriously, if I point the script to another folder with permissions 777, it returns success. But my open_basedir has no value. I have safe_mode=on and allow_url_fopen=off, but I don't think that should explain it?

这是Apache Httpd 2.0上的PHP 5.3.10.

This is PHP 5.3.10 on Apache Httpd 2.0.

推荐答案

我遇到了完全相同的问题. PHP报告在/tmp/myoutputfile中打开文件没有问题,但是该路径中没有文件.然后我做了

I had exactly the same problem. PHP reported no problem with opening file in /tmp/myoutputfile, but no file was in that path. Then I did

find / -name "myoutputfile"

并在/tmp/systemd-…/myoutputfile中找到它. 我在Google上找到了这篇文章. 因此,就我而言,这是Systemd和Apache Httpd的组合.我希望这会对某人有所帮助.

and found it in /tmp/systemd-…/myoutputfile. I've found this article on Google.
So, in my case, it was a Systemd and Apache Httpd combination. I hope this will help to someone.

这篇关于尽管具有777权限并且没有open_basedir值,但无法使用php写入/tmp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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