note 44607 added to function.mkdir
| From: | matt_DOTbevan_ATmarginsoftware_DOTcom at osu1 dot php dot net | Date: | Tue, 10 Aug 2004 23:06:41 +0000 |
| Subject: | note 44607 added to function.mkdir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-79885@lists.php.net to get a copy of this message | ||
As I was unable to use some of the more esoteric examples of a mkdir_p routine, I hashed out my own.
One of the major differences with mine is it does not use any substrs, though they would probably
be faster - my solution is easier to follow. (And works; one of them ran into an infinite loop
attempting to create '/'... ;)
<?
// Returns true when directories were created.
function mkdir_p($target) {
// If the path already exists && is a directory, all is well.
// If the path is not a directory, we've a problem.
if (file_exists($target)) {
if (!is_dir($target)) return false;
else return true;
}
// Attempting to create the directory may clutter up our display.
if ( @mkdir($target) ) return true;
// If the above failed, attempt to create the parent node, then try again.
if ( mkdir_p(dirname($target)) ) return mkdir_p($target);
return false;
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.mkdir.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+44607
Delete -- http://master.php.net/manage/user-notes.php?action=delete+44607&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+44607&report=yes
Search -- http://master.php.net/manage/user-notes.php