File write permissions error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Nunners
Forum Commoner
Posts: 89
Joined: Tue Jan 28, 2003 7:52 am
Location: Worcester, UK
Contact:

File write permissions error

Post 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
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post 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").
Post Reply