Home · Articles · Simplest Photo Gallery · Articles

articles

Simplest PHP Gallery

This is by far, the simplest way to create a photo gallery using PHP. If you can make it better (but keeping the code the same size or smaller) please let me know.


<?php
   $d = dir('./');
   $i = 0;
   while(false !== ($e = $d->read())){
       if(strpos($e,'.gif')){
           ++$i;
           echo '<img src="'.$e.'"/>'.chr(10);
           if(!($i%5))
               echo '
'; } } ?>

All you need to do is crop/resize the images and drop them in a folder, then use this PHP script which to read those images (with the same .gif file extension) from the specified folder. It will display those images on the page and insert a line break after each 5th image.

With a small modification you can modify this script to use thumbnails or a lightbox popup. Surely it can't get any smaller/easier than this!

Note: I didn't write this particular script so I cannot take credit for it.


Fri Oct 16th, 2015

This article hasn't been commented yet.

Write a comment

5 + 8 =