I don't know of any specific tutorials that will help with your problem, but I recently built this for a client. You can see the results at http://www.ftconline.org.uk - use the Assemblies link in the side menu.
<?php
function builder ($in) {
//build the markup for the table cells
while (count($in)%3 != 0) {
array_push($in, '<td> </td>');
}
return $in;
}
function row_builder ($in) {
//build the markup for the table rows
for ($i=0; $i<count($in); $i++) {
array_push($in[$i], "</tr>\n");
array_unshift($in[$i], '<tr>');
$in[$i] = implode("", $in[$i]);
}
return $in;
}
$dir = scandir('./assemblies');
for ($i=0; $i<2; $i++) {
array_shift($dir);
}
$num = count($dir);
for ($i=0; $i<$num; $i++) {
$file = array_shift(explode(".", $dir[$i]));
$dir[$i] = $file;
}
$dir = array_unique($dir);
$img = NULL;
$str = NULL;
$i=0;
$img_array = array();
$str_array = array();
$txt_array = array();
//read the files in the directory and determine what they are and then
//determine if they have images or not
foreach ($dir as $file) {
$gif = "./assemblies/$file.gif";
$jpg = "./assemblies/$file.jpg";
$pps = "./assemblies/$file.pps";
$link = "<a href='{$_SERVER['PHP_SELF']}?find=assembly&name=$file'>";
$name = str_replace("_", " ", $file);
if (file_exists($pps) && (file_exists($gif) || file_exists($jpg))) {
//build the image link
$img .= '<td>';
$img .= $link;
if ($gif) {
$img .= "<img src='$gif' alt='$file' />";
} else {
$img .= "<img src='$jpg' alt='$file' />";
}
$img .= '</a></td>';
//build the string link
$str .= "<td>$link$name</a></td>";
//write the arrays
$img_array[$i] = $img;
$str_array[$i] = $str;
$img = NULL;
$str = NULL;
} else if (file_exists($pps)&& !(file_exists($gif) || file_exists($jpg))) {
$txt .= "<td>$link$name</a></td>";
$txt_array[$i] = $txt;
$txt = NULL;
}
$i++;
}
//build the relevant arrays with mark up
$img_array = row_builder(array_chunk(builder($img_array), 3));
$str_array = row_builder(array_chunk(builder($str_array), 3));
$txt_array = row_builder(array_chunk($txt_array, 3));
//build the display table with images
echo '<table style="width:100%; text-align:center;" >';
for ($i=0; $i<count($img_array); $i++) {
echo $img_array[$i];
echo $str_array[$i];
}
echo '</table><br />';
//build any remaining text links
echo '<table style="width:100%; text-align:center;" >';
for ($i=0; $i<count($txt_array); $i++) {
echo $txt_array[$i];
}
echo '</table>';
?>
The requirement was to link an image link to a downloadable .pps file, and if no image was available to provide a link anyway - there would also be a variable number of files in the required directory at any one time.
I hope that this helps you with your problem.