1

I'm trying to write into a text file via PHP. My problem is that PHP always just clears the file instead of writing in it.

$fp = fopen('status.txt', 'w+');
fwrite($fp, "test");
fclose($fp);

I guess this depends on some permission issues. But I can't figure out what to change. At the moment the permission of the PHP file is:

-rwxrwx---  1 www-data www-data  1980 Feb 18 11:25 test8.php

the permission of textfile is:

-rwxrwx---  1 www-data www-data     0 Feb 18 11:25 status.txt

I'm using apache2 on my Raspberry Pi. The PHP script and the text file are stored in Apache main directory /var/www/

Amal Murali
  • 75,622
  • 18
  • 128
  • 150
  • I don't think that PHP has permissions to empty a file but not to add bytes. Have you configured PHP to display error messages? What do `fopen()` and `fwrite()` return? – Álvaro González Feb 18 '14 at 12:08
  • fopen returns "Resource id#3" and fwrite just returns 0 – user3323213 Feb 18 '14 at 12:19
  • Have you understood my question about configuring PHP to display error messages? Do you need help on that? – Álvaro González Feb 18 '14 at 12:29
  • yes what do you mean exactly? – user3323213 Feb 18 '14 at 12:34
  • PHP often generates an error message with a text that explains what's wrong and gives a clue on how to fix it. You can configure PHP to display it or omit it. What is your case? – Álvaro González Feb 18 '14 at 12:48
  • Please note that you can (and should) edit the original question when you need to provide further details; code in comments is unreadable. Whatever, I'll take that as a *no* — please have a look at [turn on errors](http://stackoverflow.com/a/5680885/13508). – Álvaro González Feb 18 '14 at 13:21

0 Answers0