View Full Version : Editing Pages CHMOD!!!

12-30-2007, 12:57 AM

I'm having trouble with a script I have made to edit files on my website.

I was wondering if anybody could help me becaus eit has stopped working.

This is what I have:
$page = stripslashes($_POST['page']);
$content = stripslashes($_POST['content']);
$return = stripslashes($_POST['return']);
$done = "temp_edit.php";
$fp = fopen($page,"w+") or die ("Error opening file in write mode!");
$fd = fopen($done,"w+") or die ("Error opening file in write mode!");
fputs($fp, $content);
fputs($fd, $return);
fclose($fp) or die ("Error closing fp!");
fclose($fd) or die ("Error closing fd!");
echo"<html><meta http-equiv=\"refresh\" content=\"0; url=editpage.go.php\"></html>";

The only problem is it doesn't open the files. I have this script in the root of the web so it can edit all files in public_html.

I have been trying many different alternatives but have had no luck.

The chmod on all the files intended to be edited is 775 but it still doesn't open. It only works when its 777 but I can't use that because anybody could change it.

Does anybody see what i have done wrong or missed?



12-30-2007, 01:20 AM
if you want the permissions to be 755 (owner=read/write/execute, group=read/execute,other=read/execute) then the file needs to be owned by the same user that the web-server is running as, which could be anything depending on your server (www-data, www, nobody, apache are some common default apache usernames...). You can either chown the file so as to be owned by this user, if you have root access, or write some php-code that will create the files and run it from your browser.

12-30-2007, 03:18 AM
PHP has the chown() (http://php.net/chown)/chmod() (http://php.net/chmod) functions as well that you can use to manipulate the permissions if the file is owned by the webserver's user.