Last active
February 12, 2022 15:59
-
-
Save nagiyevelchin/d6087c1c32ed56d498e596b92fc1943d to your computer and use it in GitHub Desktop.
Recursively create directory in PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Makes directory | |
* @link http://stackoverflow.com/questions/5425891/check-if-directory-exists-php | |
* @param string $pathname The directory path. | |
* @param int $mode [optional]<p> | |
* The mode is 0777 by default, which means the widest possible | |
* access. For more information on modes, read the details | |
* on the <b>chmod</b> page. | |
* </p> | |
* @since 11/23/12 12:43 PM | |
* @return bool <p><b>INT</b> on success or <b>FALSE</b> on failure. | |
* 1 - The directory $pathname was successfully created. | |
* </p> | |
*/ | |
function mkdir($pathname, $mode = 0777) { | |
$p = ""; | |
$pathname = explode('/', $pathname); | |
foreach ($pathname as $path) { | |
$p .= $path . "/"; | |
if (!file_exists($p)) { | |
if (!mkdir($p, $mode)) { | |
return false; | |
} | |
} | |
} | |
return 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment