How to create a directory recursively in php, recursive creation in php_PHP tutorial

WBOY
Release: 2016-07-13 10:08:25
Original
1288 people have browsed it

How to create a directory recursively in php, create recursively in php

The example in this article describes the method of recursively creating a directory in PHP, and I would like to share it with you for your reference.

The specific implementation code is as follows:

<&#63;php
function mk_dir($path){
 //第1种情况,该目录已经存在
 if(is_dir($path)){
 return;
 }
 //第2种情况,父目录存在,本身不存在
 if(is_dir(dirname($path))){
 mkdir($path);
 }
 //第3种情况,父目录不存在
 if(!is_dir(dirname($path))){
 mk_dir(dirname($path));//创建父目录
 mkdir($path);
 }
}
$path = './e/b/c/f';
mk_dir($path);
&#63;>
Copy after login

Replaced with ternary operation, the code is as follows:

<&#63;php
function mk_dir($path){
 //第1种情况,该目录已经存在
 if(is_dir($path)){
 return;
 }
 //三元运算
 return is_dir(dirname($path)||mk_dir(dirname($path)&#63;mkdir($path):false;
}
$path = './e/b/c/f';
mk_dir($path);
&#63;>
Copy after login

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/951640.htmlTechArticleHow to create a directory recursively in php, php recursive creation This article describes the method of recursively creating a directory in php, share it with everyone For your reference. The specific implementation code is as follows: phpfunction mk_...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!