PHP批量删除小于10K的文件实例

admin 2019-7-15 1309

<?php
function get_allfiles($path,&$files) {  
    if(is_dir($path)){  
        $dp = dir($path);  
        while ($file = $dp ->read()){  
            if($file !="." && $file !=".."){  
                get_allfiles($path."/".$file, $files);  
            }  
        }  
        $dp ->close();  
    }  
    if(is_file($path)){  
        $files[] =  $path;  
    }  
}  
     
function get_filenamesbydir($dir){  
    $files =  array();  
    get_allfiles($dir,$files);  
    return $files;  
}  
     
$filenames = get_filenamesbydir("./hotels/hotelimg");  
//删除指定文件
foreach ($filenames as $value) {  
    $filesize=abs(filesize($value));
    if($filesize<10240){    //小于10K
        echo $value."<br />";//输出被删除的文件名
        unlink($value);
    }
}


欢迎联系本站长QQ:3216572
最新回复 (0)
返回