note 44654 added to function.mkdir
| From: | bart at cdasites dot com | Date: | Thu, 12 Aug 2004 06:05:23 +0000 |
| Subject: | note 44654 added to function.mkdir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-74523@lists.php.net to get a copy of this message | ||
The mkdir_p function submitted by saint at corenova.com is nice and simple, but errors when trying
to create several directories in a tree, eg:
/foo/bar/baz/1
/foo/bar/baz/2
/foo/bar/baz/3
Adding a check before the mkdir function fixes this.
// Amended Function:
function mkdir_p($target)
{
if (is_dir($target)||empty($target)) return 1; // best case check first
if (file_exists($target) && !is_dir($target)) return 0;
if (mkdir_p(substr($target,0,strrpos($target,'/'))))
if (!file_exists($target)) return mkdir($target); // crawl back up & create dir tree
return 0;
}
Thx for the function Saint, made my life easier :)
----
Manual Page -- http://www.php.net/manual/en/function.mkdir.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+44654
Delete -- http://master.php.net/manage/user-notes.php?action=delete+44654&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+44654&report=yes
Search -- http://master.php.net/manage/user-notes.php