|  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: 2011-04-08 18:16 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:
Status: Open Package: Filesystem function related
PHP Version: 5.* OS: *
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [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.*
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Fri May 14 11:01:23 2021 UTC