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.
According to the error message displayed, there is no folder
/tmp/. Perhaps the tmp folder is somewhere else than the root?This error will not show if the file actually doesn't exist, as it will attempt to create it.
Method
xalso returns a warning if the file already exists. (doc: http://www.php.net/manual/en/function.fopen.php)I think this also goes for another reason this could go wrong, is the user which executes PHP doesn't have rights to write in the
/tmp/folder.