PHP Created File | SSH Unable to delete (permission allowed)

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);
    }
+5
source share
1 answer

mkdir works well, but the second argument is not the permission that it will use in the mode that the system will use with your current umask to calculate the permissions for the installation. From the manual:

umask, umask().

script, :

$oldUmask = umask(0); // disable umask
mkdir($path, 0777);
umask($oldUmask);  // reset the umask
+2

All Articles