Faqts : Computers : Programming : Languages : PHP : Common Problems : Files : Tips and Tricks : File Handling

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

3 of 5 people (60%) answered Yes
Recently 3 of 5 people (60%) answered Yes

Entry

Why "not rewritable"? I try to modify txt-file but get "not writable". I've tried to chmode Help :-)

Apr 28th, 2004 16:13
Mike Chavez, Paul Dunkel,


This happened to me once, not sure if you're suffering from the same 
problem though, so bear with me:
I created a file using appened mode:
$visits = fopen("./_private/visits.log", "a");
Then I wrote some info to it and closed the file. When I opened the 
file in Pico though and tried to erase some entries manually. It came 
up with "File not writable!". After trying to chmod it (and all 
failures) I found out the problem:
When php creates a file, it is assigned the group ownership "nobody" 
and the owner "nobody" and Linux sets file permissions as such. Read 
only for everyone, and write permissions only when the file is created 
in PHP. Since you probably belong to a group (mine was webscripting) 
and have a username (mine was mchavez) you get the dillemma:
user "mchavez" from group "webscripting" wants to change the 
file "visits.log" which belongs to "nobody" in the group "nobody". So, 
I as Linux say "CHMOD failed!"
Once the script is done, the permissions are changed back to prevent 
tampering. The only way I saw around this is to create a blank file 
and set the permissions yourself, then open the file using "r+" or "w".