Very Simple File Repository

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Locked
KevinR

Very Simple File Repository

Post by KevinR »

Hi All

I needed a quick download facility for my site. All it had to do was list the files in a nominated directory and present them for download along with a few details i.e. date/size.

Here it is (as a user plugin)

1. Create new plugin called "filelist".

2. Insert the following code:

$base_dir = 'uploads/';
$showpath = "no";
if (isset($params['dir']))
{
$base_dir = $params['dir'];
}
if (isset($params['showpath']))
{
$showpath = $params['showpath'];
}
if ($showpath == "yes") {
echo "Directory listing for: $base_dir";
}
echo "";
echo "";
echo "Name";
echo "Date";
echo "Size";
echo "";

$directory = dir($base_dir);
$directories_array = array();
$files_array = array();

while ($file = $directory->read()) {
if(is_file("$base_dir$file"))

{
$filesize = filesize("$base_dir$file");
if ($filesize >(1024*1024)) {$sizestr = number_format($filesize/(1024*1024))." MB";} else {
if ($filesize >(1024)) {$sizestr = number_format($filesize/1024)." KB";} else {
$sizestr = number_format($filesize)." B";
}
}
$newfile = str_replace("_" , " ", $file);
$newfile = str_replace("\." , " ", $newfile);
if ($rowstyle == "odd")
{$rowstyle = "even";} else {$rowstyle = "odd";}
echo "";
echo "$newfile ";
echo " " . date ("d F Y", filemtime("$base_dir$file"))." ";
echo " $sizestr ";
echo "";

}
}

$directory->close();

echo "";

That's it. Short and sweet.

Call it like this:

{filelist dir="uploads/filerep/"}

Options are:

dir (req) please use trailing /
showpath (opt) toggles display of File Path in output (defaults to no)

Enjoy!
KevinR

Very Simple File Repository

Post by KevinR »

Nearly forgot

Add this to your stylesheet and change them to suit your look n feel:

.filelist {
text-decoration: none;
}
tr.odd {
}
tr.even {
background-color: #c0c0c0;
}
.filelist th {
background-color: #606060;
color: #ffffff;
}
Locked

Return to “Modules/Add-Ons”