|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69351 recursive mkdir fails with parent (dot dot) directory in path and symlink
Submitted: 2015-04-01 22:18 UTC Modified: 2021-10-10 04:22 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: dave2008 at buchananville dot net Assigned: cmb (profile)
Status: No Feedback Package: Directory function related
PHP Version: 5.4.39 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
16 - 7 = ?
Subscribe to this entry?

 [2015-04-01 22:18 UTC] dave2008 at buchananville dot net
Running recursive mkdir fails when there is a ".." directory in the path, and a symbolic link is present:


The problem is that it is is expanding the path string in place instead of following the physical filesystem.  After it traverses into a/d, the ".." directory actually takes you somewhere else.  Not to "a".  In bash this is like `cd -P`.

It worked like this in previous versions (at least on PHP 5.3.3 and before).

Where previous versions of PHP have acted this way, I think it is best for backwards compatibility for this to work.

It looks like this was broken when the fix for bug #55124 was applied:

it made it use expand_filepath_with_mode() with the CWD_EXPAND.  Maybe it should have used CWD_REALPATH instead?  Just a guess...

Test script:



Expected result:
On PHP 5.3.3 it runs with no output

Actual result:
PHP Warning:  mkdir(): Permission denied in /var/autofs/home/dave/test-recursive-mkdir.php on line 7


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-10-26 19:42 UTC] nemecek at wienfluss dot net
I was investigating this issue for a CMS we use and can confirm the problem for the following PHP versions:
* 5.4.16
* 5.4.30
* 5.4.38
* 5.4.44
* 5.4.45
* 5.5.14
* 5.5.22
* 5.5.26
* 5.5.28
* 5.5.30
* 5.5.35
* 5.6.0
* 5.6.2
* 5.6.6
* 5.6.12
* 5.6.16
* 5.6.21
* 7.0.6

In the described test case, the call "mkdir('a/d/../e',0755,false);" would correctly create the path.
 [2021-09-30 16:15 UTC]
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2021-09-30 16:15 UTC]
I cannot reproduce this with PHP-7.4.  Can anybody else still
reproduce with any of the actively supported PHP versions[1]?

[1] <>
 [2021-10-10 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Jun 13 19:01:36 2024 UTC