PHP 封装函数删除文件夹内的文件 [ 新手入门 ]
<?php
/**
 * 删除文件夹内的文件
 *
 * @param $dir
 * @return bool
 */
public static function delDirFile($dir)
{
    if (! file_exists($dir)) {
        return true;
    }
    if (is_dir($dir)) {
        $dh = opendir($dir);
        while ($file = readdir($dh)) {
            if ($file != "." && $file != "..") {
                $fullpath = $dir . "/" . $file;
                if (! is_dir($fullpath)) {
                    unlink($fullpath);
                }
            }
        }
        closedir($dh);
    }
}
PHP学院的中学生
            注册时间:2018-10-23
最后登录:2025-08-09
在线时长:169小时54分
    最后登录:2025-08-09
在线时长:169小时54分
- 粉丝29
- 金钱4835
- 威望30
- 积分6825

