PHP implements directory traversal deletion based on Dir class

Source: Internet
Author: User
Tags php template ftp transfer
This article mainly introduces PHP using the built-in Dir class to implement directory traversal Delete method, involving the use of the Dir class in PHP skills, with a certain reference value, the need for friends can refer to the next

The example in this article describes how PHP uses the built-in Dir class to implement directory traversal removal. The implementation method is as follows:

function Cleardir ($dir) {if (file_exists ($dir)) {  if (!is_dir ($dir))   exit ("{$dir} is not a directory");  else  {   $dirObj = dir ($dir);   while ($file = $DIROBJ->read ())   {    if (Is_dir ($dir. ') /'. $file) && $file!== '. ' && $file!== ' ... ')    {     Cleardir ($dir. ') /'. $file);     if (@!rmdir ($dir. ' /'. $file))       echo "no permission to delete {$dir}/{$file} directory <br/>";    }    ElseIf ($file!== ' && $file!== ' ... ')    {     if (unlink ($dir. ') /'. $file))       echo "{$file} file successfully deleted <br/>";}}}  } else  exit ("{$dir} does not exist");} Cleardir ('./demo ');

Summary : The above is the entire content of this article, I hope to be able to help you learn.

Related recommendations:

Php method for FTP transfer of files based on Curl

Implementation of multi-dimensional array traversal and unset deletion method in PHP

PHP template and JS upload plug-in combination to implement a non-flush upload method

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.