Image Gallery from directory
Hi,
I want to pick out all the images in a specific folder and display them in a gallery view
e.g.
image 1 image 2 image3
image 4 image 5 image6
image 7
does anyone know how to do this?
Thanks
Carl
Hi,
I want to pick out all the images in a specific folder and display them in a gallery view
e.g.
image 1 image 2 image3
image 4 image 5 image6
image 7
does anyone know how to do this?
Thanks
Carl
Hi Carl,
Sure thing... the first thing you want to do is build an array from the folder's contents.
You would use the "scandir" command, such as $imagegal = scandir('yourFolder');
Once you have the array, loop through it with something like a "for each" loop and then test to see if each file is an image. You have to do this because a lot of times, there will be hidden files in a folder for notes or other things.
You can test if it is an image simply by making an if statement with getimagesize. For example: if (getimagesize($loopIteration)
This works because if it is not an image, it won't create a value there.
So you could have inside your for each loop of the scandir array,
<?php
if (getimagesize($i)) { ?>
<div class"yourClass"><img src="/yourFolder/$i" /></div>
<?php } ?>
Let me know if you need more details... I only had a few moments to post this... I can send you an email later or post more details when I get home tonight.
Best regards,
Brian
Thanks for the reply Brian
If you could, please can you write the whole code out, I have used the scandir and it seems to be picking out all the images in my folder but it is just showing 7 images boxed with no images.
Also, do you know how to align the images in a row so that on row 1 there are 3 images, on row two there are 3 images, and so on...
Thanks
Carl
Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.
These out-of-the-box solutions provide you proven, tested applications that can be up and running now. Build a store, a gallery, or a web-based email solution.