删除指定文件夹下全部文件

// 删除指定目录下的全部文件
function deleteFolderFiles($dir) {
    $dh = opendir($dir);
    while ($file = readdir($dh)) {
        if($file != "." && $file != "..") {
            $fullpath = $dir."/".$file;
            if(!is_dir($fullpath)) {
                unlink($fullpath);
            } else {
                deleteFolderFiles($fullpath);
            }
        }
    }
    closedir($dh);
}
点赞

发表回复

电子邮件地址不会被公开。必填项已用 * 标注