displaying images from directory php

They have: 20 posts

Joined: May 2005

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,

They have: 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.

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.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.