PHP is unable to open a file for writing - but it does exist

Posted by asdasdas on Stack Overflow See other posts from Stack Overflow or by asdasdas
Published on 2010-04-27T06:51:00Z Indexed on 2010/04/27 6:53 UTC
Read the original article Hit count: 372

Filed under:
|
|
|
|

I am trying to write to a file. I do a file_exists check on it before i do fopen and it comes up 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.

© Stack Overflow or respective owner

Related posts about php

Related posts about file-io