...

View Full Version : Getting all the images from a folder and displaying them



Ludatha
01-26-2008, 03:56 PM
My picture upload system works by giving each member their own folder created when they registered. When they upload pictures, it puts them in that folder, now I want to create a script that will display all the pictures on a page, resized to 100x100 with 3 columns and unlimited rows. Any ideas on this?

the-dream
01-26-2008, 04:41 PM
check out the dir functions on php.net then do a while loop and put all the image names into <img> tags. Like This:


<?php
if ($handle = opendir('../thumbs/')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".." && $file != ".DS_Store" && substr($file, 0, 1) !== '.') {
echo '<img style="border: 1px solid #666666;" src="../thumbs/'.$file.'" width="200" height="110" /><br><br><b>thumbs/'.$file.'</b><br><br><br>';
}
}
closedir($handle);
}
?>

Wrote that just for you ;) !

It also removes . and .. and .DS_Store ;)

Ludatha
01-26-2008, 06:20 PM
Hey, thanks allot, after a bit of fiddling I got it to work :)

kbluhm
01-26-2008, 06:46 PM
$folder = '/images/user'; // specify images folder
$images = glob( $folder . '/*.*' ); // grab images
$images = array_chunk( $images, 3 ); // split it into rows of 3

echo '<table>'; // start table
foreach ( $images as $row ) // iterate rows
{
echo '<tr>';
foreach ( $row as $img ) // iterate columns
{
echo '<td><img src="', $img, '" width="100" height="100" /></td>'; // display image
}
echo '</tr>';
}
echo '</table>'; // end table

the-dream
01-26-2008, 07:18 PM
You're welcome.

Have fun ;) !



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum