Download the latest Version Updated: July 24, 2006
fileview.php action:Last edited by SmaugDragon:
Replaces old-style internal links with new pipe-split links.
Fri, 20 May 2016 07:38 UTC [diff]
Replaces old-style internal links with new pipe-split links.
Fri, 20 May 2016 07:38 UTC [diff]
The only variable is "location" set to the location of the directory you want to show files from.
save as actions/fileview.php
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
{{fileview location="uploads/*/*.*"}} all files in all subdirectorys of uploads !!!
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.)
Tested on FreeBSD, Apache Server. I don't know what windows would do leave comment
Please comment if you find this action helpful It is my first "published" code and I would love to hear back from the community.
<?php
#
# Displays a table of specified files from a local directory.
#
# *** SECURITY NOTICE ***
# Currently this script has the ability to show ANY file on the local system
# I am working on a fix. I believe that a fix could be made that would only
# show files in the ./uploads/UserName/directory I just have to write it.
#
# Credit:
# This action is derived from a script I wrote to display downloads for php-nuke
# Credit should be given to the author of the files action for the funtion
# bytesToHumanReadableUsage (see below)
#
# @package Actions
# @name FileView
#
# @author {@link http://wikkawiki.org/SmaugDragon SmaugDragon}
# @version 0.9
# @since Wikka 1.1.6.0
#
# @input Url $location optional: the url of the files you want displayed.
#
# wildcards work fine ie.
#
# uploads /*/*.* all files in all directories under uploads
# uploads/ps_*.jpg all jpg files in uploads with names starting with ps_
#
# @Other Settings on|off $md5checksum_on off by default set to 1 for md5 checksum of files or 0 for off
#
# @todo 1.) Restrict which files a user can show
# 2.) I have to make files download instead of displaying that should fix 90% of my security worries.
#
/* CSS Info */
echo '<style type="text/css">
table.fv {border:1px solid #000; border-collapse:collapse; font-family:arial,courier,sans-serif; font-size:90%; }
td.fv,th.fv{border:0px solid #000; border-collapse:collapse; padding:5px; }
thead th.fv{text-align:center; background:#9cf; }
tbody th.fv{text-align:center; background:#69c; }
tbody td.fv{text-align:right; background:#DDDDDD; }
#ic{width: 0px;}
#nm{width: 80px; text-align: left; }
#sz{width: 80px; text-align: right; }
#mf{width: 80px; text-align: right; }
#cd{width:120px; text-align:right; font-family:courier; }
</style>';
$md5checksum_on = 0; /* calculate md5 checksums (1 = yes | 0 = no) */
if (!$location) { $location = "uploads/*.*"; } /* if location is not specified show all files in uploads */
/* Taken from WikkaWakka actions/files.php */
if (! function_exists('bytesToHumanReadableUsage')) {
function bytesToHumanReadableUsage($bytes, $precision = 2, $names = '')
{
if (!is_numeric($bytes) || $bytes < 0) {
return false;
}
for ($level = 0; $bytes >= 1024; $level++) { $bytes /= 1024; }
switch ($level)
{
case 0: $suffix = (isset($names[0])) ? $names[0] : 'Bytes'; break;
case 1: $suffix = (isset($names[1])) ? $names[1] : 'KB'; break;
case 2: $suffix = (isset($names[2])) ? $names[2] : 'MB'; break;
case 3: $suffix = (isset($names[3])) ? $names[3] : 'GB'; break;
case 4: $suffix = (isset($names[4])) ? $names[4] : 'TB'; break;
default: $suffix = (isset($names[$level])) ? $names[$level] : ''; break;
}
if (empty($suffix)) { trigger_error('Unable to find suffix for case ' . $level);
return false;
} return round($bytes, $precision) . ' ' . $suffix;
}
}
/* End of borrowed Code */
echo "<table class=\"fv\" summary=\"This table lists the files ".$location."\">\n";
/* Comment the next 2 lines to remove the table header.*/
echo '<tr class="fv"><th class="fv" scope="col"> </th><th class="fv" scope="col">File</th><th class="fv" scope="col">Size</th><th class="fv" scope="col">Modified</th>';
if ($md5checksum_on == 1) echo '<th class="fv" scope="col">md5 Checksum</th></tr>'."\n"; else echo "</tr>\n";
foreach (glob($location) as $filename) {$filedesc = end(explode('/', $filename));
echo '<td class="fv" id="ic"> </td>';
echo '<td class="fv" id="nm"><a href='.str_replace(" ", "%20", $filename).">$filedesc</a>";
echo '<td class="fv" id="sz">'.bytesToHumanReadableUsage(filesize($filename)).'</td>';
echo '<td class="fv" id="mf">'.date ("m/d/Y", filemtime($filename)).'</td>';
if ($md5checksum_on == 1) echo '<td class="fv" id="cd">'.md5_file($filename).'</td>';
echo "</tr>\n";
}
echo '</table>';
?>
#
# Displays a table of specified files from a local directory.
#
# *** SECURITY NOTICE ***
# Currently this script has the ability to show ANY file on the local system
# I am working on a fix. I believe that a fix could be made that would only
# show files in the ./uploads/UserName/directory I just have to write it.
#
# Credit:
# This action is derived from a script I wrote to display downloads for php-nuke
# Credit should be given to the author of the files action for the funtion
# bytesToHumanReadableUsage (see below)
#
# @package Actions
# @name FileView
#
# @author {@link http://wikkawiki.org/SmaugDragon SmaugDragon}
# @version 0.9
# @since Wikka 1.1.6.0
#
# @input Url $location optional: the url of the files you want displayed.
#
# wildcards work fine ie.
#
# uploads /*/*.* all files in all directories under uploads
# uploads/ps_*.jpg all jpg files in uploads with names starting with ps_
#
# @Other Settings on|off $md5checksum_on off by default set to 1 for md5 checksum of files or 0 for off
#
# @todo 1.) Restrict which files a user can show
# 2.) I have to make files download instead of displaying that should fix 90% of my security worries.
#
/* CSS Info */
echo '<style type="text/css">
table.fv {border:1px solid #000; border-collapse:collapse; font-family:arial,courier,sans-serif; font-size:90%; }
td.fv,th.fv{border:0px solid #000; border-collapse:collapse; padding:5px; }
thead th.fv{text-align:center; background:#9cf; }
tbody th.fv{text-align:center; background:#69c; }
tbody td.fv{text-align:right; background:#DDDDDD; }
#ic{width: 0px;}
#nm{width: 80px; text-align: left; }
#sz{width: 80px; text-align: right; }
#mf{width: 80px; text-align: right; }
#cd{width:120px; text-align:right; font-family:courier; }
</style>';
$md5checksum_on = 0; /* calculate md5 checksums (1 = yes | 0 = no) */
if (!$location) { $location = "uploads/*.*"; } /* if location is not specified show all files in uploads */
/* Taken from WikkaWakka actions/files.php */
if (! function_exists('bytesToHumanReadableUsage')) {
function bytesToHumanReadableUsage($bytes, $precision = 2, $names = '')
{
if (!is_numeric($bytes) || $bytes < 0) {
return false;
}
for ($level = 0; $bytes >= 1024; $level++) { $bytes /= 1024; }
switch ($level)
{
case 0: $suffix = (isset($names[0])) ? $names[0] : 'Bytes'; break;
case 1: $suffix = (isset($names[1])) ? $names[1] : 'KB'; break;
case 2: $suffix = (isset($names[2])) ? $names[2] : 'MB'; break;
case 3: $suffix = (isset($names[3])) ? $names[3] : 'GB'; break;
case 4: $suffix = (isset($names[4])) ? $names[4] : 'TB'; break;
default: $suffix = (isset($names[$level])) ? $names[$level] : ''; break;
}
if (empty($suffix)) { trigger_error('Unable to find suffix for case ' . $level);
return false;
} return round($bytes, $precision) . ' ' . $suffix;
}
}
/* End of borrowed Code */
echo "<table class=\"fv\" summary=\"This table lists the files ".$location."\">\n";
/* Comment the next 2 lines to remove the table header.*/
echo '<tr class="fv"><th class="fv" scope="col"> </th><th class="fv" scope="col">File</th><th class="fv" scope="col">Size</th><th class="fv" scope="col">Modified</th>';
if ($md5checksum_on == 1) echo '<th class="fv" scope="col">md5 Checksum</th></tr>'."\n"; else echo "</tr>\n";
foreach (glob($location) as $filename) {$filedesc = end(explode('/', $filename));
echo '<td class="fv" id="ic"> </td>';
echo '<td class="fv" id="nm"><a href='.str_replace(" ", "%20", $filename).">$filedesc</a>";
echo '<td class="fv" id="sz">'.bytesToHumanReadableUsage(filesize($filename)).'</td>';
echo '<td class="fv" id="mf">'.date ("m/d/Y", filemtime($filename)).'</td>';
if ($md5checksum_on == 1) echo '<td class="fv" id="cd">'.md5_file($filename).'</td>';
echo "</tr>\n";
}
echo '</table>';
?>
CategoryUserContributions
Works fantastic. Adding CSS for the table was VERY nice. I can now style it to my wiki. Excellent Extension!! Very nice for my users to see what images are present in the image directory (since we are a documentation site and I require everyone to send all images to me for central storage on the server to prevent broken image links). Thanks much!
1. Please document it (see the actions in the SVN for examples). Especially you should add an phpdoc header.
2. in some cases you use "<td class=\"fv\" id=\"sz\">" or similar, which is not only harder to read then '<td class="fv" id="sz">' but slower, too.
3. I am working on the files with spaces issue (replacing them with underscores) but I want to test my version before committing it and don't have the time now.
echo '<td class="fv" id="nm"><a href='.str_replace(" ", "%20", $filename).">$filedesc</a>";
with:
echo "<td class='fv' id='nm'><a href='file://".str_replace(" ", "%20", $filename)."'>$filedesc</a></td>";