Here's a tag that I use for listing files for download...
Suppose your site sells widgets and has a combination of pdf, doc and xls files for your customers to download. You could put these files in a directory called:
uploads/docs/widgets
which would contain files like this:
uploads/docs/widgets/Widget_No_1.pdf
uploads/docs/widgets/Widget_No_2.pdf
uploads/docs/widgets/Widget_No_3.pdf
uploads/docs/widgets/Widget_No_4.pdf
uploads/docs/widgets/Widget_Uses.doc
uploads/docs/widgets/Widget_Info.doc
uploads/docs/widgets/Widget_Comparison_Chart.xls
Create a tag called listDocs containing:
Code: Select all
$directory=$config[root_path] . 'uploads/docs/' . $params["docdir"] . '/';
$handler = opendir($directory);
$stringToWrite='<p>';
while ($file = readdir($handler)) {
if ($file != '.' && $file != '..') {
$extension = substr($file, -3, 3);
$newfile = str_replace("_", " ", $file);
$stringToWrite.='<a class="'. $extension . '" href="' . $directory . $file .'">' . $newfile . '</a><br />';
}
}
closedir($handler);
$stringToWrite.='</p>';
echo $stringToWrite;
add this to your stylesheet (you may need to create other entries for the types of files you have):
Code: Select all
#main .pdf{
padding: 5px 0 5px 28px;
background-image: url(uploads/images/pdf.gif);
background-position: center left;
background-repeat: no-repeat;
color: #587A9C;
text-decoration: none;
}
#main .doc{
padding: 5px 0 5px 28px;
background-image: url(uploads/images/doc.gif);
background-position: center left;
background-repeat: no-repeat;
color: #587A9C;
text-decoration: none;
}
#main .xls{
padding: 5px 0 5px 28px;
background-image: url(uploads/images/xls.gif);
background-position: center left;
background-repeat: no-repeat;
color: #587A9C;
text-decoration: none;
}
and call the tag like this:
This will display a list of linked files with a different graphic for each type of file and the "_" (underscores) in the filenames will be replaced with spaces, making them easier to read. This allows you to upload your docs into subfolders and call the tag for each folder on different pages.
Nullig