PHP Delete Directory several methods _php tutorial

Source: Internet
Author: User
How to remove Directories in PHP This article provides three ways to delete directories in PHP, if you are looking for a delete directory or delete all the files in the PHP code to see it.

PHP Tutorial Delete Directory several methods
This article provides three ways to delete directories in PHP , if you are looking to delete directories or delete all the files in the directory PHP code to see it.

Deletedir ($dir)
{
if (RmDir ($dir) ==false && is_dir ($dir)) {
if ($DP = Opendir ($dir)) {
while (($file =readdir ($DP))! = False) {
if (Is_dir ($file) && $file! = '. ' && $file! = ' ... ') {
Deletedir ($file);
} else {
Unlink ($file);
}
}
Closedir ($DP);
} else {
Exit (' www.aimeige.com.cn not permission ');
}
}
}

Delete directory use RmDir to remove it.

For example, the folder where the current file is located downstream www.bkjia.com/a folder
@ $flag = rmdir ("www.bkjia.com/");
if ($flag)
{echo "www.zhutiai.com delete succeeded";}
Else
{echo "www.bkjia.com delete failed";}


Below is a PHP delete folder and all the files under the folder

function Deldir ($dir) {
$DH =opendir ($dir);
while ($file =readdir ($DH)) {
if ($file! = "." && $file! = "...") {
$fullpath = $dir. " /". $file;
if (!is_dir ($fullpath)) {
Unlink ($fullpath);//mb.php100.com
} else {
Deldir ($fullpath);
}
}
}

Closedir ($DH);

if (RmDir ($dir)) {
return true;
} else {
return false;
}
}


http://www.bkjia.com/PHPjc/445402.html www.bkjia.com true http://www.bkjia.com/PHPjc/445402.html techarticle How to remove Directories in PHP This article provides three ways to delete directories in PHP, if you are looking for a delete directory or delete all the files in the PHP code to see it. PHP Tutorials ...

  • 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.