使用php codigniter排除文件夹中文件数量不同扩展名的文件? count(*格式,此格式除外(webm))

时间:2016-12-10 06:42:18

标签: php codeigniter

我想在一个文件夹中获取一些视频文件,假设.mp4,.mp3,.flv..etc扩展名并排除.webm扩展名等文件。如何用php condeigniter执行此操作?

1 个答案:

答案 0 :(得分:0)

编写像这样的自定义函数

function getCount(){
$overAllCount = 0;
$directory = base_url().'uploads';
$mp4count = glob($directory . '*.mp4');
$mp3count = glob($directory . '*.mp3');
$flvcount = glob($directory . '*.flv');

if ( $mp4count !== false )
{
    $filecount = count( $mp4count );
    $overAllCount += $filecount;
}
if ( $flvcount !== false )
{
    $filecount = count( $flvcount );
    $overAllCount += $filecount;
}
if ( $mp3count!== false )
{
    $filecount = count( $mp3count);
    $overAllCount += $filecount;
}
return $overAllCount;
}