PHP Recursive Create directory

Source: Internet
Author: User

/** * Recursive Create directory * @param  [string] $path [created directory] * @return [Type]       [description] */function Mk_dir ($path) {//If directory exists return t Ureif (Is_dir ($path)) {return true;} If the parent directory exists create directory if (Is_dir (DirName ($path))) {return mkdir ($path);} Recursively finds the parent directory Mk_dir (dirname ($path)); return mkdir ($path);}

function Mk_dir ($path) {//directory exists return Tureif (Is_dir ($path)) {return true;} Parent directory exists or recursively finds parent directory, creates directory return Is_dir (dirname ($path)) | | Mk_dir (DirName ($path))? mkdir ($path): "false";}

/** * Iterate to create a directory (the iteration I understand is the process from minimum accumulation to maximum) * @param  [string] $path [Create directory name] * @return [Type]       [description] */function Mk_di R ($path) {$arr = array ();//The directory decomposition is stored in the array while (!is_dir ($path)) {Array_unshift ($arr, $path);//Inserts an element into the array header $path = DirName ($ path);} if (empty ($arr)) {return ture;} foreach ($arr as $v) {mkdir ($v);}}

After php5 you can use the mkdir third parameter, recursively create a directory mkdir ("directory Name", 0777,true);

function Deldir ($path) {if (!is_dir ($path)) {return null;} $DH = Opendir ($path), while (($row = Readdir ($DH))!== false) {if ($row = = "." | | $row = = "...") {continue;} if (!is_dir ($path. "/" . $row) {unlink ($path. "/" . $row);} Else{deldir ($path. "/" . $row);}} Closedir ($DH); rmdir ($path); return true; Will output 1} on the page

PHP Recursive Create directory

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.