note 44607 deleted from function.mkdir by aidan
| From: | aidan@php.net | Date: | Sun, 03 Oct 2004 13:37:03 +0000 |
| Subject: | note 44607 deleted from function.mkdir by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-77826@lists.php.net to get a copy of this message | ||
Note Submitter: matt_DOTbevan_ATmarginsoftware_DOTcom
----
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;
}
?>