note 96188 deleted from function.mkdir by danbrown
| From: | danbrown@php.net | Date: | Fri, 12 Feb 2010 23:16:01 +0000 |
| Subject: | note 96188 deleted from function.mkdir by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-165927@lists.php.net to get a copy of this message | ||
Note Submitter: support at addcomment dot ru
----
how to create 'dir1/dir2/dir3/...' folders, with full error support:
<?
#recursive dir creating
function mkdirr($p,$m) {
$e="mkdir: unable";
foreach(explode('/',trim($p,'/')) as $d) {
if(empty($d)||$d=='/') break;
if(!@is_dir($d)) {
if(file_exists($d)) die("{$e} to create folders: '{$p}' -- '{$d}'
EXISTS AS FILE!");
if(!@mkdir($d,$m)) die("{$e} to create folder: '{$d}' in path:
'{$p}' .. permissions?");
}
if(!@chdir($d)) die("{$e} chdir({$d}) , path: '{$p}' .. huh?");
}
}
?>
mkdir('/upload/files/21-02/',077)
has been created/checked dirs with permissions 0777 (rxwrxwrxw)