Forum Moderators: coopster
i am opening a text file for appending, the file opens no problem but when i try to write data to it I get this error message from the server;
supplied argument is not a valid stream resource
what am I doing wrong?
ps. permissions are all set up 777 on all files used.
thx for the help, its driving me nuts
variables are obviously set previously
before i explain, here is the new code (with added vars i used):
<?php
$filename = 'test.txt';
$name = 'kumar';
if (is_writable($filename))
{
if (!$file=fopen($filename, "ab") )
{
echo "The file could not be opened";
}
else
{
if (fwrite($file, $name))
{
echo "file writen successfully";
fclose($file);
}
else
{
echo "file not written";
}
}
}
else
{
echo "the file is not writable";
}
?>
now there are few things that i found.
1. unclosed else loop..else opened in line 4 in the code u posted above is not closed.
2. line 2 and line 5 i see u have tried to test for true or false. this not the way to do it(or so i think, it doesnt work anyway). im sure there is away to explicitly do this, but what ur doing is not the right way anyway, thats where its gone wrong, really.
if ($file=fopen($filename, "ab")
the if loop would execute if the reult was true anyway and else would only execute if it was false,s o as u see, there is no need to explictly do it in your case.
besides, im sure its just me, but never heard of ab as file opening mode.
hope this helps
kumar