删除文件夹

删除文件夹


 

示例:

<?php
function delete_file($path){
    if(is_dir($path)){
        if($res = opendir($path)){
            while($file=readdir($res)){
                if($file != '.' && $file != '..'){            
                    if(is_file($path.'/'.$file)){
                        unlink($path.'/'.$file);
                    }else if(is_dir($path.'/'.$file)){
                        delete_file($path.'/'.$file);
                    }
                }
            }
            closedir($res);
            rmdir($path);
        }
    }else if(is_file($path)){
        unlink($path);
    }
}

相关函数:

unlink() 函数删除文件。
rmdir() 函数删除空的目录。


 

posted @ 2019-03-29 14:53  学知无涯  阅读(177)  评论(0编辑  收藏  举报