note 26340 deleted from function.mkdir by aidan
| From: | aidan@php.net | Date: | Sun, 03 Oct 2004 13:39:49 +0000 |
| Subject: | note 26340 deleted from function.mkdir by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-77840@lists.php.net to get a copy of this message | ||
Note Submitter: cweiske at cweiske dot de
----
// mkdirs
// makes dirs, even if parents don't exist - they are made, too
// checks if this dir exists, then if the parent, then its parent...
// -> fast for cases where the parents will exist most times
// -> slow if the root dir doesn't exist
function mkdirs( $strPath, $nPermission)
{
strstr( PHP_OS, "WIN") ? $strPathSeparator = "\\" : $strPathSeparator =
"/";
$strDirname = substr( $strPath, 0, strrpos( $strPath, $strPathSeparator));
if( is_dir( $strDirname)) {
return true;
}
$arMake = array();
array_unshift( $arMake, $strDirname);
do
{
$bStop = true;
$nPos = strrpos( $strDirname, $strPathSeparator);
$strParent = substr( $strDirname, 0, $nPos);
if( !is_dir( $strParent)) {
$strDirname = $strParent;
array_unshift( $arMake, $strDirname);
$bStop = false;
}
} while( !$bStop);
if( count( $arMake) > 0) {
foreach( $arMake as $strDir) {
mkdir( $strDir, $nPermission);
}
}
return true;
}//function mkdirs( $strPath, $nPermission)