get all the images from a folder in php

Sksudip picture Sksudip · Jun 15, 2013 · Viewed 136.4k times · Source

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

Please advice me, how can I get images name.

Answer

sharif2008 picture sharif2008 · Jun 15, 2013

try this

$directory = "mytheme/images/myimages";
$images = glob($directory . "/*.jpg");

foreach($images as $image)
{
  echo $image;
}