php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #37946 mkdir recursive creates wrong owner for parent directories
Submitted: 2006-06-28 11:32 UTC Modified: 2006-06-29 21:28 UTC
From: oscar dot de dot lathouder at gmail dot com Assigned:
Status: Not a bug Package: Directory function related
PHP Version: 5.1.4 OS: Fedora Core 5
Private report: No CVE-ID: None
 [2006-06-28 11:32 UTC] oscar dot de dot lathouder at gmail dot com
Description:
------------
The recursive option of mkdir() creates wrong owners for created parents.







Reproduce code:
---------------
Executed file:
-rw-rw-rw- 1 thisuser mygoup  5900 Jun 28 09:32 test.php

saveLocation:
/mnt/shared/

ls -al /mnt/shared/
drwxrwxrwx 1 thisuser mygroup     0 Jun 28 09:21 .
drwxr-xr-x 5 root     root     4096 Jun 23 15:11 ..
(note: server is MS Windows 2000 server, executing server is Fedora Core 5. 'thisuser' has read/write permissions on server as well)

Code:
$saveLocation = /mnt/shared/1/2/3/
if (!file_exists($saveLocation) && !is_dir($saveLocation)) mkdir($saveLocation,0777,true);



Expected result:
----------------
ls -al /mnt/shared/
drwxrwxrwx 1 thisuser mygroup     0 Jun 28 09:21 .
drwxr-xr-x 5 root     root     4096 Jun 23 15:11 ..
drwxrwxrwx 1 thisuser mygroup     0 Jun 28 09:21 1

ls -al /mnt/shared/1/
drwxrwxrwx 1 thisuser mygroup     0 Jun 28 09:21 .
drwxrwxrwx 1 thisuser mygroup     0 Jun 28 09:21 ..
drwxrwxrwx 1 thisuser mygroup     0 Jun 28 09:21 2

ls -al /mnt/shared/1/2/
drwxrwxrwx 1 thisuser mygroup     0 Jun 28 09:21 .
drwxrwxrwx 1 thisuser mygroup     0 Jun 28 09:21 ..
drwxrwxrwx 1 thisuser mygroup     0 Jun 28 09:21 3


Actual result:
--------------
ls -al /mnt/shared/
drwxrwxrwx 1 thisuser  mygroup    0 Jun 28  2006 .
drwxr-xr-x 5 root         root 4096 Jun 23 15:11 ..
drwxrwxrwx 1 root         root    0 Jun 28  2006 1

ls -al /mnt/shared/1/
drwxrwxrwx 1 root         root    0 Jun 28  2006 .
drwxrwxrwx 1 thisuser  mygroup    0 Jun 28  2006 ..

Errorlog:
[Wed Jun 28 10:58:43 2006] [error] [client xx.xx.xx.xx] PHP Warning:  mkdir() [<a href='function.mkdir'>function.mkdir</a>]: Permission denied in /var/www/html/test.php on line 2, referer: http://xx.xx.xx.xx/test.php

When I execute the same script again, it will create another directory (2), but exits with the same error.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-06-28 11:42 UTC] tony2001@php.net
mkdir() has nothing to do with the permissions, it just creates directories.
Not PHP problem.
 [2006-06-28 22:16 UTC] oscar dot de dot lathouder at gmail dot com
why does mkdir() create the first dir (1), failes to make the others, when recursive=true?
 [2006-06-29 21:28 UTC] oscar dot de dot lathouder at gmail dot com
I'm not sure about the 'standard owner' created by PHP(which is 'root'), but the solution was found in using umask().

<?php
$saveLocation= "/testdir/test1/test2/test4";
if (!is_dir($saveLocation)){
        $oldumask = umask(0);
        mkdir($saveLocation,0666,true);
        umask($oldumask);
}
?>

Sorry.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 14:01:32 2024 UTC