php.net |  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
Votes:5
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
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
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
Description:
------------
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 
exist.

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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-05-26 22:33 UTC] stefan-nowak-php at mailinator dot com
User TrentTompkins provides a workaround function at:
http://php.osmirror.nl/manual/de/function.file-put-contents.php#84180

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] jani@php.net
-Package: Feature/Change Request +Package: Filesystem function related -Operating System: +Operating System: * -PHP Version: 5.2.9 +PHP Version: 5.*
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC