note 46819 deleted from function.mkdir by nlopess
| From: | nlopess@php.net | Date: | Tue, 10 Jan 2006 19:36:42 +0000 |
| Subject: | note 46819 deleted from function.mkdir by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-101511@lists.php.net to get a copy of this message | ||
Note Submitter: andrei at bizland dot ro
----
Here is a better function to create multiple directories :
function mkDirE($dir,$dirmode=700)
{
if (!empty($dir))
{
if (!file_exists($dir))
{
preg_match_all('/([^\/]*)\/?/i', $dir,$atmp);
$base="";
foreach ($atmp[0] as $key=>$val)
{
$base=$base.$val;
if(!file_exists($base))
if (!mkdir($base,$dirmode))
{
echo "Error: Cannot create ".$base;
return -1;
}
}
}
else
if (!is_dir($dir))
{
echo "Error: ".$dir." exists and is not a directory";
return -2;
}
}
return 0;
}