note 15118 added to function.mkdir
| From: | KilerCris at Mail dot com | Date: | Tue, 28 Aug 2001 19:12:37 +0000 |
| Subject: | note 15118 added to function.mkdir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-17259@lists.php.net to get a copy of this message | ||
I noticed that this function will only attempt to create the last directory in the path, so
mkdir("./newdir1/newdir2/newdir2",0700);
won't work. I wrote this function to do it.
function mkpath($path,$mode = 0700) {
$dirs = explode("\\",realpath($path));
$path = $dirs[0];
for($i = 1;$i < count($dirs);$i++) {
$path .= "/".$dirs[$i];
if(!is_dir($path))
mkdir($path,$mode);
}
}
Note: I wrote this on windows, where realpath starts with x:\ (x being drive letter)
http://www.php.net/manual/en/function.mkdir.php