$dir     = ‘images’;

if ($handle = opendir($dir)) {

while (false !== ($entry = readdir($handle))) {

$files[] = $entry;

}

//$images=preg_grep(‘/\.jpg$/i’, $files);

$images=preg_grep(‘/\.(jpg|jpeg|png|gif)(?:[\?\#].*)?$/i’, $files);

foreach($images as $image)    {

echo $image;

}

closedir($handle);

}

1 Answers
Best Answer

Lets look at the PHP show images from folder script:
 //Path to folder which contains images
$dirname = “images/”;

//Use glob function to get the files
$images = glob($dirname.”*”);

foreach($images as $image){
//print the image
echo ‘<a href=”‘.$image.'” target=”_blank”><img src=”‘.$image.'” height=”100″ width=”100″ /></a>’;
}

Please login or Register to submit your answer
Not the answer you are looking for? Browse other questions tagged or ask your own question.