I am using PHP (version 5.2.9) running with the Apache web server (version 2.2.11) on Kubuntu Linux. I have installed both from source (not the repositories).
I am having difficulty using fwrite() to write to a text file.
I am using (something like) the following code:
$TEXTFILE = fopen('textfile.txt', 'a') || die('Cannot open error log.');
fwrite($TEXTFILE, "This is a some text.\n") || die('Cannot write to error log.');
fclose($TEXTFILE);
fclose($MESSAGES);
but am getting this error message:
Warning: fwrite(): supplied argument is not a valid stream resource in [PHP file] on line 37
Cannot write to error log.
The only suggestions I can find from Googling is to fix the permissions but I already have the folder set to 777 permissions and the file itself (after it has been created) also has 777 permissions.
The funny thing is:
1. It does create the text file in the folder if it doesn't already exist but will not write to it (so I just get an empty text file).
2. Using the (fairly new) PHP function file_put_contents (which apparently does all of the above) works, including creating and writing to the file.
I'm stumped. Any suggestions?
Thanks.
I am having difficulty using fwrite() to write to a text file.
I am using (something like) the following code:
$TEXTFILE = fopen('textfile.txt', 'a') || die('Cannot open error log.');
fwrite($TEXTFILE, "This is a some text.\n") || die('Cannot write to error log.');
fclose($TEXTFILE);
fclose($MESSAGES);
but am getting this error message:
Warning: fwrite(): supplied argument is not a valid stream resource in [PHP file] on line 37
Cannot write to error log.
The only suggestions I can find from Googling is to fix the permissions but I already have the folder set to 777 permissions and the file itself (after it has been created) also has 777 permissions.
The funny thing is:
1. It does create the text file in the folder if it doesn't already exist but will not write to it (so I just get an empty text file).
2. Using the (fairly new) PHP function file_put_contents (which apparently does all of the above) works, including creating and writing to the file.
I'm stumped. Any suggestions?
Thanks.