Okay, I am a beginner at this and I am trying to piece everything together. I am trying to create a file directory/download page. The way it will work is there will be a list of products and each product has 4 or 5 files associated with it that need to be listed with that product. I want the thumbnail to show up. I tried doing str_replace on the file name but I obviously am doing something wrong because it isnt replacing anything merely adding them to the top as you can see from my screenshot. The second image is what I am actually going for. Any help would be appreciated. I dont even really know what to ask at this point. So, should each product have its own folder. and then create an array with one for the different file types then have it go to the next directory and so on an so forth. I have been trying all these different things now to no avail so I must be doing something wrong. PLEASE help.
Matt
<?PHP
function getFileList($dir, $recurse=true)
{
// array to hold return value
$retval = array();
// add trailing slash if missing
if(substr($dir, -1) != "/") $dir .= "play/";
// open pointer to directory and read list of files
$d = @dir($dir) or die("getFileList: Failed opening directory $dir for reading");
while(false !== ($entry = $d->read())) {
// skip hidden files
if($entry[0] == ".") continue;
if(is_dir("$dir$entry")) {
$retval[] = array(
"name" => "$dir$entry/",
"hires" => 0,
"lastmod" => filemtime("$dir$entry")
);
if($recurse && is_readable("$dir$entry/")) {
$retval = array_merge($retval, getFileList("$dir$entry/", true));
}
} elseif(is_readable("$dir$entry")) {
$retval[] = array(
"name" => "$dir$entry",
"size" => filesize("$dir$entry"),
"lastmod" => filemtime("$dir$entry")
);
}
}
$d->close();
return $retval;
}
?>
<?PHP
$dirlist = getFileList("play/");
/* sample output
Array
(
[0] => Array
(
[name] => images/background0.jpg
[type] => image/jpeg
[size] => 86920
[lastmod] => 1077461701
)
[1] => ...
)
*/
?>
<?PHP
// output file list as HTML table
echo "<table border='1'>\n";
echo "<tr><th>Name</th><th>Size</th><th>Last Mod.</th></tr>\n";
foreach($dirlist as $file) {
echo "<tr>\n";
echo '<img src="play/play.png" style="width: 20px; height: 20px">';
echo "<td width='200'><a href=\"{$file['name']}\">",basename($file['name']),"</a></td>\n";
//string that needs to be customized
$rawstring = "{$file['name']}";
//placeholders array
$placeholders = array("{$file['name']}");
//male replace values array
$thumbvals = array('<img src="play/play.png" style="width: 20px; height: 20px">');
//thumb string
$thumbstr = str_replace($placeholders, $thumbvals, $rawstring);
echo $thumbstr ;
echo "<td width='100'>{$file['size']}</td>\n";
echo "<td width='200'>",date('r', $file['lastmod']),"</td>\n";
echo "</tr>\n";
}
echo "</table>\n\n";
?>