Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
487 views
in Technique[技术] by (71.8m points)

fopen - Can't write to /tmp with php, despite 777 permissions and no open_basedir value

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());

This returns the error message:

failed to open stream: No such file or directory.

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?

This is PHP 5.3.10 on Apache Httpd 2.0.

question from:https://stackoverflow.com/questions/10752396/cant-write-to-tmp-with-php-despite-777-permissions-and-no-open-basedir-value

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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"

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...