Page 1 of 1

File write permissions error

Posted: Wed Jan 11, 2006 6:09 am
by Nunners
I've got a config file frmo a third party tool running on my Linux box, which I want to write single lines to the end of.

Here's my script:

Code: Select all

$user="  s/".$_GET["User_ID"].";".$_GET["Name"];
if (is_writable($filename_users)) {
   if (!$handle = fopen($filename_users, 'a+')) {
         echo "Cannot open file ($filename_users)";
         exit;
   }
   if (fwrite($handle, $user) === FALSE) {
       echo "Cannot write to file ($filename_users)";
       exit;
   }
   echo "Success, wrote ($user) to file ($filename_users)";
   fclose($handle);
} else {
   echo "The file $filename_users is not writable";
}
I have another small script that reads the file, for purely information sake, to see the users listed.
However, everytime I try and write to it, I get the error file not writable.

Can someone point me in the direction of what file permissions I need - I have tried jsut chmod 777, but this didn't resolve it; in fact it caused a different error: cannot open file!

Any help would be greatly appreciated!
Thanks
Nunners

Posted: Wed Jan 11, 2006 8:58 am
by Maugrim_The_Reaper
Who owns the file? (ownership) If the file is not owned by your user, and its permissions currently prevent writing/reading you won't be able to change those permissions.

So in order to effect chmod 777, you'll need to use the user who owns the file. Or try root. Using root - you can probably use chown to make the apache process the owner (usually "nobody").