Home > Backend Development > PHP Tutorial > PHP directory creation and recursive unlimited creation and deletion of directories implementation code_PHP tutorial

PHP directory creation and recursive unlimited creation and deletion of directories implementation code_PHP tutorial

WBOY
Release: 2016-07-13 16:55:39
Original
716 people have browsed it

The article is very simple. Two examples implement the PHP directory creation and recursive unlimited creation and deletion of directories. Friends in need can refer to it. We use mkdir and rddir for the example.

The following is the program code:

 代码如下 复制代码
function mkdirs($dir)
{
if(!is_dir($dir))
{
if(!mkdirs(dirname($dir))){
return false;
}
if(!mkdir($dir,0777)){
return false;
}
}
return true;
}
mkdirs('div/css/layout');

Same idea, PHP uses rmdir and unlink to recursively delete multi-level directories:

The code is as follows
 代码如下 复制代码

function rmdirs($dir)
{
$d = dir($dir);
while (false !== ($child = $d->read())){
if($child != '.' && $child != '..'){
if(is_dir($dir.'/'.$child))
rmdirs($dir.'/'.$child);
else unlink($dir.'/'.$child);
}
}
$d->close();
rmdir($dir);
}

Copy code
function rmdirs($dir)
{
$d = dir($dir);
while (false !== ($child = $d->read())){
if($child != '.' && $child != '..'){
if(is_dir($dir.'/'.$child))
rmdirs($dir.'/'.$child);
else unlink($dir.'/'.$child);
}
}
$d->close();
rmdir($dir);
}

http://www.bkjia.com/PHPjc/631669.htmlwww.bkjia.comtrue
http: //www.bkjia.com/PHPjc/631669.html
TechArticle
The article is very simple. Two examples implement PHP directory creation and recursive unlimited creation and deletion of directories. Friends in need For reference, we use mkdir and rddir for examples. Below...
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