Some cases like image in image gallery, you need to list all the
images from directory and display in browser. In this article am going
to explain you how to list all images from a directory using PHP. We are
going to use PHP inbuilt function like globe() to fetch all images from
a folder.
You can view demo and download how to list all Images from a directory using PHP:
Hope that this will help you.

PHP get images from Folder
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 //Note that we have used " * " inside this function. If you want to get only JPEG or PNG use //below line and commnent $images variable currently in use $images = glob($dirname."*"); //Display image using foreach loop foreach($images as $image){ //print the image to browser with anchor tag (Use if you want really :) ) echo '<a href="'.$image.'" target="_blank"><img src="'.$image.'" height="100" width="100"></a><br>'; }Now save the above file and run. PHP will look inside the folder and fetch all the images and display in browser.If your folder contains not only images some other files also means, we need to put an array of accepted file formats.
Hope that this will help you.
No comments:
Post a Comment