How to get only images using scandir in PHP?

后端 未结 6 1321
逝去的感伤
逝去的感伤 2020-11-27 15:52

Is there any way to get only images with extensions jpeg, png, gif etc while using

$dir    = \'/tmp\';
$files1 = scand         


        
6条回答
  •  独厮守ぢ
    2020-11-27 16:05

    The actual question was using scandir and the answers end up in glob. There is a huge difference in both where blob considerably heavy. The same filtering can be done with scandir using the following code:

    $images = preg_grep('~\.(jpeg|jpg|png)$~', scandir($dir_f));
    

    I hope this would help somebody.

提交回复
热议问题