This article illustrates how PHP deletes all directories and files in a specified directory. Share to everyone for your reference. The implementation method is as follows:
<?php/* * Delete all directories and files (or specify files) in the specified directory * Extensible add some options (such as whether to delete the original directory, etc.) * Remove file sensitive operation use * @param $dir directory path * @param array $f
ILE_TYPE Specifies the file type */function Delfile ($dir, $file _type= ') {if (Is_dir ($dir)) {$files = Scandir ($dir); Open the directory//list all the files in the directory and remove them.
And.. foreach ($files as $filename) {if ($filename!= '. ' && $filename!= ' ... ')
{if (!is_dir ($dir.. $filename)) {if (Empty ($file _type)) {unlink ($dir. '/'. $filename); }else{if (Is_array ($file _type)) {//Regular matches the specified file if (Preg_match ($file _type[0), $file
Name) {unlink ($dir. '/'. $filename);
}else{//Specifies the file containing some strings if (False!=stristr ($filename, $file _type)) {
Unlink ($dir. '/'. $filename);
}}}else{Delfile ($dir. '/'. $filename);
RmDir ($dir. '/'. $filename); }}}else{if (File_exists ($dir)) uNlink ($dir); } delfile (DirName (__file__), ' HTML ');
I hope this article will help you with your PHP programming.