Bug #72651 [Opn->Csd]: Recursive mkdir doesn't create last directory
| From: | ktierney at akamai dot com | Date: | Fri, 22 Jul 2016 18:38:49 +0000 |
| Subject: | Bug #72651 [Opn->Csd]: Recursive mkdir doesn't create last directory | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-202508@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=72651&edit=1
ID: 72651
User updated by: ktierney at akamai dot com
Reported by: ktierney at akamai dot com
Summary: Recursive mkdir doesn't create last directory
-Status: Open
+Status: Closed
Type: Bug
Package: Apache related
Operating System: Ubuntu 14.04
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
mkdir works fine. Problem caused by code.
Previous Comments:
------------------------------------------------------------------------
[2016-07-22 15:49:44] ktierney at akamai dot com
Description:
------------
(PHP5.5.9) In creating a directory using "mkdir('./results/16/07/22/G2/4', 0777,
true), all but the last (4) subdirectory is created. The function returns true, no exception is
thrown. This happens when the PHP script containing the line is run on an Apache2.4/7 web server.
When the same function is run in interactive PHP, it works fine. safe_mode is off in both php.ini
files. I substituted the CreateDirPath() function for it, but I get the same behavior on the server
and interactively.
Test script:
---------------
$test['path'] = './results/16/07/22/G2/4';
mkdir($test['path'], 0777, true);
-- and --
function CreateDirPath($dirpath, $rwx = 0777)
{ $x = preg_replace('/\.\//', '', $dirpath);
$dlst = explode('/', $x);
$cwd = $xdir = getcwd();
try
{ foreach ($dlst as $d)
{ $dt = trim($d);
if ($dt)
{ $xdir = "$xdir/$dt";
if (!is_dir($xdir))
{ if (!mkdir($dt, $rwx)) return false;
}
if (!chdir($xdir)) return false;
}
}
return chdir($cwd);
}
catch(Exception $e) { return false; }
}
Expected result:
----------------
I expect all the directories to be created with a permission of 0777.
CreateDirPath() does this interactively, but behaves the same as mkdir() when run under Apache.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=72651&edit=1