Hi all, i am building a image gallery and cannot figure out how i can display all the images from a directory in a table and specify the amount of rows to use?
can anyone help?
regards,
Hi all, i am building a image gallery and cannot figure out how i can display all the images from a directory in a table and specify the amount of rows to use?
can anyone help?
regards,
nuk3 posted this at 02:57 — 9th February 2006.
He has: 238 posts
Joined: May 2002
<?php$dir_path = "C:/appserv/www/images/\";
$dir_url = \"http://localhost:8080/images/\";
$num_cols = 1;
$max_rows = 4;
$ext = array(\"jpg\", \"png\", \"jpeg\", \"gif\", \"bmp\");
$files = array();
if( $handle = opendir($dir_path) )
{
while ( false !== ($file = readdir($handle)) )
{
for($i=0;$i<sizeof($ext);$i++)
{
if(strstr($file, \".\".$ext[$i]))
$files[] = $file;
}
}
closedir($handle);
}
$total_images = count($files);
echo '<table width=\"100%\" cellpadding=\"6\" cellspacing=\"5\" border=\"1\">';
$new_row = 1;
$limit = ($max_rows > $total_images) ? $total_images : $max_rows;
for ($i = 0; $i < $limit; $i++)
{
if ($new_row == 1)
{
echo \"<tr>\";
}
echo <<<text
<td><img src=\"$dir_url{$files[$i]}\"></td>
text;
if ( ($new_row == $num_cols) or ($i == ($limit - 1)) )
{
echo \"</tr>\n\n\";
$new_row = 1;
}
else
{
$new_row++;
}
}
echo \"</table>\";
?>
Give that a whirl.
nuk3.com | Free funny flash movies and addictive games
benf3 posted this at 11:30 — 9th February 2006.
They have: 20 posts
Joined: May 2005
hey thanks i will give it a try? It is alot different to the scripts i have been coming up with!! WIll let you know how i get on.