Linux SSH
I am creating a file in php using
if (!is_dir(DIR_FILE))
mkdir(DIR_FILE, 0777);
$filename = DIR_FILE . $id . '.txt';
$handle_cf = fopen($filename, 'a');
fwrite($handle_cf, $data . "\n");
fclose($handle_cf);
chmod($filename, 0777);
chown($filename, "usr111"); // usr111 = username
chgrp($filename, "usr111"); // usr111 = group that is also attached to apache
The file receives the following permissions.
-rwxrwxrwx 1 apache apache 1447 Apr 4 12:48 D.txt
-rwxrwxrwx 1 apache apache 1447 Apr 4 12:48 E.txt
however, when you try to delete the file under a regular user account (usr111). I get the following error:
[usr111@host session]$ rm D.txt
rm: cannot remove `D.txt': Permission denied
NOTE. I can delete the file as root.
PLAY FOUND! although I used the mode setting on mkdir for php. For some reason this did not work. I have added the following.
if (!is_dir($dir)) {
mkdir($dir, 0777);
chmod($dir, 0777);
}
source
share