I recently made a similar snippet for my site to just show filelistings. It has some extra features (and misses some of this one ). I will just list them here for reference. If interested I could put up the code so it can be integrated (code is still a bit messy, but it works).
- Sort by filename, date, size or extension
- Sort ascending or descending
- Show only selected extensions
- Show icons based on file extension (.doc files will have Word icon, .pdf will have Acrobat icon etc...)
- Delete files (for selected webgroups)
I have one pending request from the website manager and that is to have the possibility to rename files. Right now she has to delete the file and upload it again. (I use it in combination with the fileupload snippet posted somewhere else on this forum)
***** Update 03/01/06 ******
After seeing the comments here and some of the work done, I have updated the FileDownload Snippet.
I added the code for usign a template, thanks to Robin for getting that going.
I also added the ability to get a description from a chunk (Great idea Susan), so you can update the info in the manager.
The ability to have alternating odd/even row highlighting is still there as well.
*******************
What version of php are you using. I think the error may be because I pass an array by referance in a foreach loop. I think that was added in php 5. If that is the case I will have to see if there is a way to do this to make it compatible with php4.
I will work on getting the die comments taken out.
Briggsy:
What version of php are you using. I think the error may be because I pass an array by referance in a foreach loop. I think that was added in php 5. If that is the case I will have to see if there is a way to do this to make it compatible with php4.
foreach ($files as &$fOutput) { if ($fOutput['name'] == $fileInfo[0]) { $fOutput['description'] = $fileInfo[1]; break;
reset($files); while (list($key, $value) = each($files)) { if ($files[$value]['name'] == $fileinfo[0]) { $files[$key]['description'] = $fileinfo[1]; break; } }
No probs, just substitute foreach loop with a while loop and work directly with the array, than it wont matter what php version your using.
No need to pass copy or reference, just work directly with array. Note: I just did this off top of head, may need a minor change.
foreach ($files as $file) { $tpl2 = $tpl['row']; if ($useHlt) { if ($i++ & 1) { $tpl2 = str_replace("<tr>","<tr class='$oddClass'>",$tpl2); } else { $tpl2 = str_replace("<tr>","<tr class='$evenClass'>",$tpl2); } }
$imgTypes = array( 'jpg' => 'file-image.png', 'png' => 'file-image.png', 'pdf' => 'pdf.gif', 'txt' => 'file-document.png', 'zip' => 'file-archive.png', 'default' => 'file-generic.png', );