PHP is_writable() returns true but file_put_contents() returns false

PHP

I'm having trouble writing to a file even though is_writable() returns true. Of course, the file exists and is apparently readable. Here is the code:

$file = "data";
echo file_get_contents($file)."<br>";
echo is_writable($file) ? "is writable<br>" : "not writable<br>";
if (file_put_contents($file, "ghijkl", FILE_APPEND) === FALSE) echo "failed<br>";
echo file_get_contents($file)."<br>";

And here is the output:

abcdef
is writable
failed
abcdef

Best Answer

Maybe you're trying to write to a directory, not a file - that is, something that's writable but you cannot append to. Just a guess.

Related Topic