Created
February 26, 2014 17:19
-
-
Save openam/9234101 to your computer and use it in GitHub Desktop.
Make Directories Recursively in PHP 4
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 | |
| /** | |
| * rmkdir is a recursive mkdir function. PHP4 doesn't have the recursive paramater, | |
| * so this was added to use on a PHP 4 server. These references could be changed back to | |
| * | |
| * @param string $path | |
| * @param int $mode of the file permissions | |
| * @param boolean $recursive not used, but is there so that you can easly change from rmkdir (PHP 4) to mkdir(PHP 5) easily | |
| * @return boolean true if directories were successfully created | |
| */ | |
| function rmkdir($path, $mode = 0777, $recursive = true) { | |
| $path = str_replace("\\", "/", $path); | |
| $path = explode("/", $path); | |
| $return = false; | |
| $rebuild = ''; | |
| foreach($path as $key => $p) { | |
| if (strlen($p) > 0) { | |
| if(strstr($p, ":") != false) { | |
| echo "\nFound : in $p\n"; | |
| $rebuild = $p; | |
| continue; | |
| } | |
| if (in_array($p, array('.', '..')) && $key == '0') { | |
| $rebuild .= "$p"; | |
| } else { | |
| $rebuild .= "/$p"; | |
| } | |
| if(!is_dir($rebuild)) { | |
| if (mkdir($rebuild, $mode)) { | |
| $return = true; | |
| } else { | |
| $return = false; | |
| } | |
| } | |
| } | |
| } | |
| return $return; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice script. Thanks for sharing. :-)
I would like to share a literary I have coded with the same goal.
Example of usage:
Full documentation: https://github.com/MathiasReker/php-file-permissions