Home > Article > Backend Development > php delete directory and all files_PHP tutorial
function del($name) {
if (!is_dir($name)) {
return @unlink($name);
} else {
$dir = opendir($name);
while( $file = readdir( $dir ) ) {
if (($file=='.')||($file=='..')) continue;
if (is_dir($name.'/'.$file)) $this->del($name.'/'.$file);
else echo basename($file), @unlink($name.'/'.$file) ? ' Success!' : ' False.', '
';
}
closedir($dir);
}
return @rmdir($name);
}