Return total number of files within a folder using PHP

前端 未结 10 943
花落未央
花落未央 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 20:48

    The aforementioned code

    $count = count(glob("*.{jpg,png,gif,bmp}"));
    

    is your best best, but the {jpg,png,gif} bit will only work if you append the GLOB_BRACE flag on the end:

    $count = count(glob("*.{jpg,png,gif,bmp}", GLOB_BRACE));
    

提交回复
热议问题