I get this error when using fopen (write mode).
Warning: fopen(search/sub2_GetViewsNow01.txt) [function.fopen]: failed to open stream: Permission denied in /home/jancom/public_html/tools/TubePromoter/members/search.php on line 321
I did chmod 775 both search.php and directory, but it didn’t help. Any ideas?
There are a couple of things in here that don’t make much sense.
Is it your intention to truncate the file if it already exists? You have an if statement there that looks to see if the file exists, but it opens it in ‘w’ mode which will effectively delete all info in the existing file. If you want to write to the end of the file you should open it in ‘a’ mode in that first fopen call. However, it’s still going to get truncated as you didn’t do an ‘else’ Here’s how I would write it, assuming that you want to keep the data if the file already exists.
You also need to read those error messages carefully. Changing the permissions of search.php isn’t relevant. The error message is telling you that the error occurred at line 321 of search.php because that’s where the fopen() was that tried to open the file for writing. The actual error, as it says, is that it failed to open the stream described in the error message as ‘fopen(search/sub2_GetViewsNow01.txt)’.
So, to cut a long story short… it’s saying ‘look at line 321 of search.php because that’s where the error occurred when I tried to fopen() your file’.