Writing to a text file on the server?


I’m trying to set up a RSVP form which will take form data and write it to a simple text file on the dreamhost server. I am submitting this form to a PHP script. Right now a simple test code looks like:

$myFile = fopen(‘rsvp_data.txt’,‘w’);
fwrite($myFile,‘This is a test\n’);

rsvp_data.txt already exists on the server, but I can not get the form to write to the file. I’ve tried changing the permissions on it to all sorts of combinations, and it won’t write. However, if I log in to the server through SSH, and run the script though the command line “php -f”, the file gets written to. Anyone know what I’m doing wrong?

I’m new to PHP, but have used CGI, perl, and a variety of other languages before. I’m using the DreamHost shared solution, if that matters.


if the file already exists, change ‘w’ (write) to ‘a’ (append).


Thanks bobocat. I just realized my mistake… I was trying to debug the code, and I had commented out the call to the php processor… Everything is working now–and thanks for the append tip as well. :slight_smile: