Posts tagged gallery

PHP: Display all files/pictures in a folder

2

If we want to create a quick gallery of files/pictures, it is quite a pain to do so manually. And since this is some code I'm always reusing I thought I might share it here with everyone else:

Let's suppose we are in the base directory (www.mysite.com/gallery.php) and the pictures are in a folder named pictures (www.mysite.com/pictures/), open gallery.php and where you want the pictures to appear, use this code:

$handle = opendir(dirname(realpath(__FILE__)).'/pictures/');
		while($file = readdir($handle)){
			if($file !== '.' && $file !== '..'){
				echo '<img src="pictures/'.$file.'" border="0" />';
			}
		}

This code is really easy to understand, we first define a variable "$handle", which will contain the handle to the absolute path of the folder (I always go for absolute paths since I find them much safer)
dirname(realpath(__FILE__)) returns the absolute path to the current file (gallery.php) and then we add to the end of it /pictures/

Then, we loop through all the files in the directory, that simple if statement I used is to prevent some the function returning . or .. as file names sometimes. We then display the image in standard html

Take care!
Alex

Best free icons

0

This is my list of the best free icon services around, all with a preview and a description ;)

To visit just click on the title or in the image. Most of the icon sets below are both in png and ico formats, and the download page can be found within the preview page in most of the times.

Icon Buffet

"Our icons are painstakingly created pixel by pixel, and each collection features a variety of formats and sizes. We're sure you'll be delighted when you take a bite from the Buffet."
A lot of different icon packs, some good, some bad...

Icon Buffet

Silk Icons

This is probably the most well-known icon set in the internet! Featuring an icon for almost anything you could think of, great for educational sites and big categorized navigation menus.

Mini icons:

Another version by FamFamFam, in a smaller size, but still with that delightful look they give their icon sets!

Flag icons

Yet another great set by FamFamFam, featuring 247 flags of most countries in the world. Great for multilingual sites which offer translated content...

Aero IconSet

A beautiful icon set with 147 icons with Desktop looks. Both in png and ico formats:

LeEsta IconSet

A beautiful set of icons also in png and ico formats. With a sort of "Noble" look, great for your desktop or retro website!

Website Icons

A very good icon resource, with the problem that the "good" icons are not free. You have a free category though, the pixel icons, which is still quite good!

Other sites:

Some other good icon resources can be found here:

If you enjoyed this list, consider bookmarking this page:

Go to Top