Web Design
Web Design Surrey Web Design Services in Surrey

Tutorial Categories

Links & Services

Mailing List

For special offers and annoucements, please enter your email address below.

Output a list of images using PHP

The following snippet creates a list of images that are in a folder using the glob function. Its far easier to use than PHP's scandir and allows you read all items of a certain file type within a specified directory. Please note that you need to use a LFS or UNC path or you can use chdir to set the correct directory first.

List of images:<br />
// Filter out everything except jpeg images.
// Put the results into an array
$images = glob("*.jpg");

//sort the images using PHPs natural sorting algorithm

//output each of the images
foreach($images as $image){
	echo $image."<br />";    
	echo "<img src='$image' width='200' height='200' /><br /><br /><br />";

Here's an example of the code above:

List of images:

Warning: chdir(): Permission denied (errno 13) in /home/sites/marcfirth/public/priv/themes/tutorials.php(309) : eval()'d code on line 21

More PHP Tutorials

Recursively Remove Files in Linux

View More...

PHP Dynamically Generated Year Dropdown

View More...

Output All PHP Session Variables

View More...

Dynamically Generated PHP Bar Graphs

View More...