Revision [14907]

This is an old revision of SmaugDragon made by SmaugDragon on 2006-07-20 12:50:50.

 

My fileview action script the only variable is "location" set to the location of the directory you want to show files from.

examples:
{{fileview location="uploads/*.*"}} will show all files in uploads directory
{{fileview location="uploads/*.zip}} will show only zip files in uploads directory
{{fileview location="uploads/pic???.jpg}} will show only jpg files with names like pic000.jpg pic001.jpg etc

Additionally you can set $md5checksum on or off in the fileview.php file to have md5checksums generated on the fly [off by default].
(Not recomended for large directories or files)

  1. <style type="text/css">
  2. table {border:1px solid #000; border-collapse:collapse; font-family:arial,courier,sans-serif; font-size:90%; }
  3. td,th{border:0px solid #000; border-collapse:collapse; padding:5px; }
  4. thead th{text-align:center; background:#9cf; }
  5. tbody th{text-align:center; background:#69c; }
  6. tbody td{text-align:right; background:#DDDDDD; }
  7. #ic{width: 0px;}
  8. #nm{width: 80px; text-align: left; nowrap;}
  9. #sz{width: 80px; text-align: right; nowrap;}
  10. #mf{width: 80px; text-align: right; nowrap;}
  11. #cd{width:120px; text-align:right; font-family:courier; nowrap;}
  12. </style>
  13.  
  14. <?php
  15.  
  16. if (!$location) { $location = "uploads/*.*"; }  /* if location is not specified show all files in uploads */
  17. $md5checksum_on = 1;                    /* calculate md5 checksums (1 = yes | 0 = no)   */
  18.  
  19.     /* Taken from WikkaWakka actions files.php */
  20. if (! function_exists('bytesToHumanReadableUsage')) {
  21.         function bytesToHumanReadableUsage($bytes, $precision = 2, $names = '')
  22.         {
  23.            if (!is_numeric($bytes) || $bytes < 0) {
  24.                return false;
  25.            }
  26. for ($level = 0; $bytes >= 1024; $level++) { $bytes /= 1024; }
  27.     switch ($level)
  28.     {
  29.     case 0: $suffix = (isset($names[0])) ? $names[0] : 'Bytes'; break;
  30.     case 1: $suffix = (isset($names[1])) ? $names[1] : 'KB'; break;
  31.     case 2: $suffix = (isset($names[2])) ? $names[2] : 'MB'; break;
  32.     case 3: $suffix = (isset($names[3])) ? $names[3] : 'GB'; break;
  33.     case 4: $suffix = (isset($names[4])) ? $names[4] : 'TB'; break;
  34.     default: $suffix = (isset($names[$level])) ? $names[$level] : ''; break;
  35.     }
  36. if (empty($suffix)) { trigger_error('Unable to find suffix for case ' . $level);
  37. return false;
  38. } return round($bytes, $precision) . ' ' . $suffix;
  39. }
  40. }
  41.     /* End of borrowed Code */
  42.  
  43. echo "<table summary=\"This table lists the files ".$location."\">\n";
  44. echo "<tr><th scope=\"col\">&nbsp;</th><th scope=\"col\">File</th><th scope=\"col\">Size</th><th scope=\"col\">Modified</th>";
  45.  
  46. if ($md5checksum_on == 1) echo "<th scope=\"col\">md5 Checksum</th></tr>\n"; else echo "</tr>\n";
  47.  
  48. foreach (glob($location) as $filename) {
  49.     echo "<td id=\"ic\"></td>";
  50.     echo "<td id=\"nm\"><a href=".$filename.">$filename</a>";
  51.     echo "<td id=\"sz\">".bytesToHumanReadableUsage(filesize($filename))."</td>";
  52.     echo "<td id=\"mf\">".date ("m/d/Y", filemtime($filename))."</td>";
  53. if ($md5checksum_on == 1) echo "<td id=\"cd\">".md5_file($filename)."</td>";
  54.     echo "</tr>\n";
  55. }
  56. echo "</table>";
  57. ?>


There are 2 comments on this page. [Show comments]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki