Bookcafe

Sunday, September 26, 2010

PHP Simple Image Gallery

It is a very easy to create a simple image gallery using PHP script. What I mean is that I'm using a PHP function glob. This function will output the name of files in the folder. If this function can display the name of the files, then of course it should be able to display the files especially image files. I used the HTML tag <img src="" /> to display the image file and thus I created a very simple image gallery. The following is the PHP code:



<?php

//path to the directory the images resides

//$directory = "http://directory/of/your/image/";

//get all image files with a .jpg extension or you other extension, just replace jpg with gif,png or others

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

//print each file name

echo "<table><tr><td style=\"vertical-align: top;\">";

foreach($images as $image)

{

echo $image;

echo "<br>";

echo "<img border=\"0\" src=\"http://directory/of/your/image/$image\" width=\"150\" height=\"100\">";

echo "<br>";

}

echo "</td></tr></table>";

?>


Image will be displayed in horizontal manner and I need to find a way so that the images can be displayed in a table layout but then that is for my next project.

No comments:

Post a Comment