I have a form that that t he client goes in and enters some data. This data is written to a text file in a directory on my server. The only way I can get this to work properly is to open the directory wide open chmod 777 but I am worried about security risks with this. Should I be worried? Is there a better way to do this?
This is what I am using:
$fh = fopen($file, 'w+');
fwrite($fh, $buff);
fclose($fh);
Thanks...
Permission problem
Moderator: General Moderators
What is the owner/group of the file and what is the owner/group which php scripts connect under? You can check this by looking at the site with an ftp program and doing a dirinfo command or similar.
I'm guessing that php uses a different owner/group to that under which the file was created. To fix that, create the file with php: thereafter php should be able to write to it with a safer CHMOD 755. You may need to CHMOD 777 the parent folder to allow php to write the file but, once it's written, the parent folder can be CHMOD'd back to 755. Php will be able to write to a file in a 755 folder with a different owner/group if the file itself has the php owner/group.
I'm guessing that php uses a different owner/group to that under which the file was created. To fix that, create the file with php: thereafter php should be able to write to it with a safer CHMOD 755. You may need to CHMOD 777 the parent folder to allow php to write the file but, once it's written, the parent folder can be CHMOD'd back to 755. Php will be able to write to a file in a 755 folder with a different owner/group if the file itself has the php owner/group.
-
scubadiveflorida
- Forum Newbie
- Posts: 10
- Joined: Wed Oct 29, 2003 9:53 am
reply
ok In the function at the begining before being written I am doing:
$permissions = `chmod 777 ../directory_name`;
Then after the fwrite I am doing:
$permissions = `chmod 755 ../directory_name`;
This does not seem to work any ideas?
$permissions = `chmod 777 ../directory_name`;
Then after the fwrite I am doing:
$permissions = `chmod 755 ../directory_name`;
This does not seem to work any ideas?
-
scubadiveflorida
- Forum Newbie
- Posts: 10
- Joined: Wed Oct 29, 2003 9:53 am
exact
$permissions = `chmod 777 /home/users/create`;
# This grabs the correct template then puts the two files together
if ($filename == '')
{
$genericfile = "file.generic";
}else{
$genericfile = "$filename";
}
$buff = get_contents($genericfile);
$buff = $tempvar.$buff;
$file = "$file.txt";
$fh = fopen($file, 'w+');
fwrite($fh, $buff);
fclose($fh);
$permissions = `chmod 755 /home/ams/amsorm_create`;
# This grabs the correct template then puts the two files together
if ($filename == '')
{
$genericfile = "file.generic";
}else{
$genericfile = "$filename";
}
$buff = get_contents($genericfile);
$buff = $tempvar.$buff;
$file = "$file.txt";
$fh = fopen($file, 'w+');
fwrite($fh, $buff);
fclose($fh);
$permissions = `chmod 755 /home/ams/amsorm_create`;
-
scubadiveflorida
- Forum Newbie
- Posts: 10
- Joined: Wed Oct 29, 2003 9:53 am
-
scubadiveflorida
- Forum Newbie
- Posts: 10
- Joined: Wed Oct 29, 2003 9:53 am