PHP Help

Out of context: Reply #4

  • Started
  • Last post
  • 14 Responses
  • D_Dot0

    <?php

    $path = "images/tees";
    $path_large = "images/tees/large";
    $title = 'Need formula here';
    $extensions = Array('.gif','.jpg','.png');
    $num_cols = 3;
    $img_width = '215';

    $images = Array();
    if(@$handle = opendir($path))
    {
    while(false!== ($file = readdir($handle)))
    {
    if($file!= '.' && $file!= '..' &&!is_dir($file) && in_array(substr($file,-4),$extensions))
    {
    $images[] = $file; // enters the image into
    }
    }
    }

    echo "<table>\n";
    echo "<colgroup>\n";
    for($i=0;$i<$num_cols;$i++)
    {
    echo "<col width='".$img_width."' />\n";
    }
    echo "</colgroup>\n<tr>\n";

    if(count($images)>0)
    {
    $i=1; // sets column counter to 1
    foreach($images as $image)
    {
    if($i==$num_cols+1)
    {
    echo "</tr>\n<tr>\n";
    $i=1;
    }
    echo "<td><a href='$path_large/$image' rel='lightbox' title='$title'><img src='$path/$image' width='$img_width' /></a></td>\n";
    $i++;
    }
    if($i <= $num_cols)
    {
    while($i<=$num_cols)
    {
    echo "<td>&nbsp;</td>\n";
    $i++;
    }
    }
    }
    else
    {
    echo "<td>No images in specified folder</td>\n";
    }
    echo "</tr>\n</table>\n";
    ?>

View thread