note 40292 deleted from function.mkdir by aidan
| From: | aidan@php.net | Date: | Sun, 03 Oct 2004 13:37:53 +0000 |
| Subject: | note 40292 deleted from function.mkdir by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-77829@lists.php.net to get a copy of this message | ||
Note Submitter: jkaufman at wamnetgov dot com
----
I modified Shaun's version of mkdir_p slightly.
1) I consider an existing directory a success, not a failure
2) If the file exists and is not a directory, then we have a possible issue and the function returns
0
3) I changed 'eregi' to 'ereg'
4) I simplified the recursive call, eliminating the if statements
function mkdir_p($target)
{
if (file_exists($target) && !is_dir($target))
return 0; // failure
if (substr($target, 0, 1) != '/')
$target = "/".$target; // prepend a slash
if (ereg('\.\.', $target) || ereg("[^a-zA-Z0-9\._\-\/]", $target))
return 0; // if illegal dirname
if (mkdir($target)) // if new dir created,
return 1; // we are successful
if (mkdir_p(substr($target, 0, (strrpos($target, '/')))) == 1)
return (mkdir_p($target));
else
return 0;
}