I am trying to write to a file. I do a file_exists
check on it before I do fopen
and it returns true
(the file does exist).
However, the file fails this code and gives me the error every time:
$handle = fopen($filename, 'w');
if($handle)
{
flock($handle, LOCK_EX);
fwrite($handle, $contents);
}
else
{
echo 'ERROR: Unable to open the file for writing.',PHP_EOL;
exit();
}
flock($handle, LOCK_UN);
fclose($handle);
Is there a way I can get more specific error details as to why this file does not let me open it for writing? I know that the filename is legit, but for some reason it just wont let me write to it. I do have write permissions, I was able to write and write over another file.