note 77383 added to function.mkdir
| From: | MichalNazarewicz at osu1 dot php dot net | Date: | Mon, 27 Aug 2007 14:34:43 +0000 |
| Subject: | note 77383 added to function.mkdir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-129835@lists.php.net to get a copy of this message | ||
On the other hand, splitting path on something else then a DIRECTORY_SEPARATOR may give unexpected
results when someone accualy wants a file name with backslash in it! Moreover, neither Alan's
nor pluto's code check for errors or return any value. Also, I don't like the
isset($folder[$i]) technique -- there is a count() function you know.
<?php
function recursive_mkdir($path, $mode = 0777) {
$dirs = explode(DIRECTORY_SEPARATOR , $path);
$count = count($dirs);
$path = '.';
for ($i = 0; $i < $count; ++$i) {
$path .= DIRECTORY_SEPARATOR . $dirs[$i];
if (!is_dir($path) && !mkdir($path, $mode)) {
return false;
}
}
return true;
}
?>
It will only fail if someone specifies a mode which does not allow owner to create new entries in
directory.
----
Server IP: 195.136.184.34
Probable Submitter: 217.96.228.130
----
Manual Page -- http://www.php.net/manual/en/function.mkdir.php
Edit -- https://master.php.net/note/edit/77383
Del: integrated -- https://master.php.net/note/delete/77383/integrated
Del: useless -- https://master.php.net/note/delete/77383/useless
Del: bad code -- https://master.php.net/note/delete/77383/bad+code
Del: spam -- https://master.php.net/note/delete/77383/spam
Del: non-english -- https://master.php.net/note/delete/77383/non-english
Del: in docs -- https://master.php.net/note/delete/77383/in+docs
Del: other reasons-- https://master.php.net/note/delete/77383
Reject -- https://master.php.net/note/reject/77383
Search -- https://master.php.net/manage/user-notes.php