Listing all images in a directory using PHP

前端 未结 8 762
悲&欢浪女
悲&欢浪女 2021-01-04 08:39

I have the code below that lists all the images in a folder, the problem is that it finds some files ( a . and a ..) that I am not sure what they are so I a

8条回答
  •  Happy的楠姐
    2021-01-04 09:08

    glob() is case sensitive and the wildcard * will return all files, so I specified the extension here so you don't have to do the filtering work

    $d = 'path/to/images/';
    foreach(glob($d.'*.{jpg,JPG,jpeg,JPEG,png,PNG}',GLOB_BRACE) as $file){
        $imag[] =  basename($file);
    }
    

提交回复
热议问题