php删除文件夹php

/ / 2020-09-23   阅读:2496
php删除文件夹...
<?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() 函数删除空的目录。

我要评论

昵称:
验证码:

最新评论

共0条 共0页 10条/页 首页 上一页 下一页 尾页
意见反馈