get all the images from a folder in php

前端 未结 9 2280
南方客
南方客 2020-12-04 14:37

I am using WordPress. I have an image folder like mytheme/images/myimages.

I want to retrieve all the images name from the folder myimages<

9条回答
  •  悲&欢浪女
    2020-12-04 15:18

    $dir = "mytheme/images/myimages";
    $dh  = opendir($dir);
    while (false !== ($filename = readdir($dh))) {
        $files[] = $filename;
    }
    $images=preg_grep ('/\.jpg$/i', $files);
    

    Very fast because you only scan the needed directory.

提交回复
热议问题