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