php---删除目录的函数

删除目录的函数

function deleteFolder($tmp_path){ 
            if(!is_writeable($tmp_path) && is_dir($tmp_path)){chmod($tmp_path,0777);} 
            $handle = opendir($tmp_path); 
            while($tmp=readdir($handle)){ 
                if($tmp!='..' && $tmp!='.' && $tmp!=''){ 
                    if(is_writeable($tmp_path.DS.$tmp) && is_file($tmp_path.DS.$tmp)){ 
                        unlink($tmp_path.DS.$tmp); 
                    }elseif(!is_writeable($tmp_path.DS.$tmp) && is_file($tmp_path.DS.$tmp)){ 
                        chmod($tmp_path.DS.$tmp,0666); 
                        unlink($tmp_path.DS.$tmp); 
                    } 

                    if(is_writeable($tmp_path.DS.$tmp) && is_dir($tmp_path.DS.$tmp)){ 
                        $this->deleteFolder($tmp_path.DS.$tmp); 
                    }elseif(!is_writeable($tmp_path.DS.$tmp) && is_dir($tmp_path.DS.$tmp)){ 
                        chmod($tmp_path.DS.$tmp,0777); 
                        delete_folder($tmp_path.DS.$tmp); 
                    } 
                } 
            } 
            closedir($handle); 
            rmdir($tmp_path); 
            if(!is_dir($tmp_path)){return true;} 
            else{return false;} 
        }

你可能感兴趣的:(php---删除目录的函数)