Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

maxterpiece

macrumors 6502a
Original poster
Mar 5, 2003
729
0
I'm trying to add a string to a TXT file on my webserver (hosted on asmallorange), and I get this error:
"Warning: fopen(story.txt) [function.fopen]: failed to open stream:
Permission denied in /tryphp.php (I abbreviated the location) on line 36

Why can't I write to the file? How can I give my script permission to edit the file? Both the file and the script are located in the exact same location on the server.

Thanks for any help you can provide!

Code:
//make addition
$myFile="story.txt";
$fh = fopen($myFile, 'a+');
fwrite($fh, $addition);
 
you'll probably find that the files in "your" webspace have an owner of "yourusername" but the webserver (apache) process is running as the http or web user, and so it doesnt have access to modify those files. ideally, see if you can give the file(s) a group that corresponds to the apache process, and make it group writable.
 
I had this exact problem a while back. It's a permissioning issue. Contact your host and ask then to set the permissions up so you can open and write data using php.
 
I had this exact problem a while back. It's a permissioning issue. Contact your host and ask then to set the permissions up so you can open and write data using php.

So I emailed my host and they said
story.txt is not writable by the nobody (the webserver ID).

You'll need to either change the permissions to 664 (allow your id and nobody write perms) or have us change the ownership to nobody to allow the webserver write access (disallows you from deleting/overwriting via ftp).

Well i would rather still have access to my file, so I'd prefer not to have them give just the webserver permission, but I don't know what they are talking about - How do I change "the permissions to 664 (allow your id and nobody write perms)." I apologize if this is something elementary, again I don't really know what I'm doing.

Thanks for the responses everyone and thanks for any further help you can provide!
 
You'll need to log into your web server via your FTP program, I use transmit. Then find your file and right click on it. Go to "Get info", much like your Mac OS X interface, you'll notice a portation at the bottom of the window that pops up that lets you check and uncheck certain permissions. Change them to as needed and hit apply. 777 is your ultimate anyone can read and edit everything. Hope this helps.
 
You'll need to log into your web server via your FTP program, I use transmit. Then find your file and right click on it. Go to "Get info", much like your Mac OS X interface, you'll notice a portation at the bottom of the window that pops up that lets you check and uncheck certain permissions. Change them to as needed and hit apply. 777 is your ultimate anyone can read and edit everything. Hope this helps.

DO NOT just go setting "777" rights without exploring other options. it means ANYONE who has access to the web server's file structure can modify your file.


I strongly suggest you explore the options mentioned above, (either ask the host for help, or change the group ownership of the file to match that of the apache process).
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.