function delfile($filename)
{
if (!file_exists($filename)) {
return;
}
if (!is_dir($filename)) {
unlink($filename);
return;
}
if (($handle = opendir($filename))) {
while (($item = readdir($handle))) {
if ($item != "." && $item != "..") {
$fullpath = $filename . '/' . $item;
if (!file_exists($fullpath)) {
continue;
}
if (is_dir($fullpath)) {
delfile($fullpath);
rmdir($fullpath);
} else {
unlink($fullpath);
}
}
}
closedir($handle);
}
}