Req #48401 [Opn->Fbk]: File & Directory Functions: Auto create intermediate directories from filepath

From: Date: Tue, 31 Aug 2021 10:14:18 +0000
Subject: Req #48401 [Opn->Fbk]: File & Directory Functions: Auto create intermediate directories from filepath
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-236193@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=48401&edit=1 ID: 48401 Updated by: cmb@php.net Reported by: stefan-nowak-php at mailinator dot com Summary: File & Directory Functions: Auto create intermediate directories from filepath -Status: Open +Status: Feedback Type: Feature/Change Request Package: Filesystem function related Operating System: * PHP Version: 5.* -Assigned To: +Assigned To: cmb Block user comment: N Private report: N New Comment: 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? Previous Comments: ------------------------------------------------------------------------ [2009-05-26 22:33:11] 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. ------------------------------------------------------------------------ [2009-05-26 22:20:30] 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 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=48401&edit=1

« previous php.bugs (#236193) next »