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

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-22 17:21:23
Original
834 people have browsed it

<?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);
        }
    }
}
?>
Copy after login


本文地址:

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

Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template