note 83265 deleted from function.mkdir by crell
| From: | crell@php.net | Date: | Wed, 29 Jun 2022 19:19:28 +0000 |
| Subject: | note 83265 deleted from function.mkdir by crell | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-218719@lists.php.net to get a copy of this message | ||
Note Submitter: GelaMu at GMail dot com
----
<?php
/**
* Makes directory and returns BOOL(TRUE) if exists OR made.
*
* @param $path Path name
* @return bool
*/
function rmkdir($path, $mode = 0755) {
$path = rtrim(preg_replace(array("/\\\\/", "/\/{2,}/"), "/", $path),
"/");
$e = explode("/", ltrim($path, "/"));
if(substr($path, 0, 1) == "/") {
$e[0] = "/".$e[0];
}
$c = count($e);
$cp = $e[0];
for($i = 1; $i < $c; $i++) {
if(!is_dir($cp) && !@mkdir($cp, $mode)) {
return false;
}
$cp .= "/".$e[$i];
}
return @mkdir($path, $mode);
}
?>