|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #48401 File & Directory Functions: Auto create intermediate directories from filepath
Submitted: 2009-05-26 22:20 UTC Modified: 2021-09-12 04:22 UTC
Avg. Score:5.0 ± 0.0
Reproduced:5 of 5 (100.0%)
Same Version:4 (80.0%)
Same OS:3 (60.0%)
From: stefan-nowak-php at mailinator dot com Assigned: cmb (profile)
Status: No Feedback Package: Filesystem function related
PHP Version: 5.* OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: stefan-nowak-php at mailinator dot com
New email:
PHP Version: OS:


 [2009-05-26 22:20 UTC] stefan-nowak-php at mailinator dot com
It would be nice if all/some of PHP's file and directory functions would 
offer a flag AUTO_CREATE_DIRS, which would then cause these functions to 
automatically create directories for the given filepath, which yet don't 

Many shell tools allow similar functionality (i.e: mkdir -p)

Reproduce code:
file_put_contents ( "/existing-dir/not-yet-existing-dir/file", "test");
// Warning: file_put_contents (existing-dir/not-yet-existing-dir/file): failed to open stream: No such file or directory

Expected result:
file_put_contents ( "/existing-dir/not-yet-existing-
dir/sub1/sub2/file.txt", "test", AUTO_CREATE_DIR);
// If my sugestion would be implemented I would then expect PHP to 
automatically create the directories:
// not-yet-existing-dir , sub1, sub2
// and the file:
// file.txt


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-05-26 22:33 UTC] stefan-nowak-php at mailinator dot com
User TrentTompkins provides a workaround function at:

And everyone can built similar workarounds. But as originally said, it 
would be nice if this feature would be included in PHP's built-in file 
and directory functions.
 [2011-04-08 18:16 UTC]
-Package: Feature/Change Request +Package: Filesystem function related -Operating System: +Operating System: * -PHP Version: 5.2.9 +PHP Version: 5.*
 [2021-08-31 10:14 UTC]
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2021-08-31 10:14 UTC]
That raises the question, though, what file permissions should be
set.  Since mkdir() allows to specify these explicitly, and it
supports the $recursive parameter, isn't that sufficient?
 [2021-09-12 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-2021 The PHP Group
All rights reserved.
Last updated: Sat Sep 25 04:03:37 2021 UTC