php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72651 Recursive mkdir doesn't create last directory
Submitted: 2016-07-22 15:49 UTC Modified: 2016-07-23 01:18 UTC
From: ktierney at akamai dot com Assigned:
Status: Not a bug Package: Apache related
PHP Version: Irrelevant OS: Ubuntu 14.04
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: ktierney at akamai dot com
New email:
PHP Version: OS:

 

 [2016-07-22 15:49 UTC] 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.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-07-22 18:38 UTC] ktierney at akamai dot com
-Status: Open +Status: Closed
 [2016-07-22 18:38 UTC] ktierney at akamai dot com
mkdir works fine. Problem caused by code.
 [2016-07-23 01:18 UTC] requinix@php.net
-Status: Closed +Status: Not a bug
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 01 15:01:38 2025 UTC