Return total number of files within a folder using PHP

前端 未结 10 942
花落未央
花落未央 2020-12-28 20:31

Is there a better/simpler way to find the number of images in a directory and output them to a variable?

function dirCount($dir) {
  $x = 0;
  while (($file          


        
10条回答
  •  南方客
    南方客 (楼主)
    2020-12-28 21:11

    I use the following to get the count for all types of files in one directory in Laravel

       $dir = public_path('img/');
        $files = glob($dir . '*.*');
    
        if ( $files !== false )
        {
            $total_count = count( $files );
            return $totalCount;
        }
        else
        {
            return 0;
        }
    

提交回复
热议问题