Home >php教程 >php手册 >删除目录及其下的文件还有问题吗?送大家一个写好的函数

删除目录及其下的文件还有问题吗?送大家一个写好的函数

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-05-22 17:21:23836browse

<?php
/**
 * c_function::dir_delete()
 * 删除目录
 * @param $file 目录名(不带/)
 * @return
 */
function dir_delete($file) {
    if (file_exists($file)) {
        if (is_dir($file)) {
            $handle = opendir($file);
            while (false !== ($filename = readdir($handle))) {
                if ($filename != "." && $filename != "..") $this->dir_delete($file . "/" . $filename);
            }
            closedir($handle);
            rmdir($file);
            return true;
        } else {
            unlink($file);
        }
    }
}
?>


本文地址:

转载随意,但请附上文章地址:-)

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn