i have just finished making my file uploads in my school project...then what i want now is to let other members download what was uploaded by others.. i have this code here and it shows the files in the upload folder but i cant download it..
<?php
echo ("<h1>File Directory:</h1>");
function getFiles($path) {
$files = array();
$fileNames = array();
$i = 0;
if (is_dir($path)) {
if ($dh = opendir($path)) {
while (($file = readdir($dh)) !== false) {
if ($file == "." || $file == "..") continue;
$fullpath = $path . "/" . $file;
$fkey = strtolower($file);
while (array_key_exists($fkey,$fileNames)) $fkey .= " ";
$a = stat($fullpath);
$files[$fkey]['size'] = $a['size'];
if ($a['size'] == 0) $files[$fkey]['sizetext'] = "-";
else if ($a['size'] > 1024) $files[$fkey]['sizetext'] = (ceil($a['size']/1024100)/100) . " K";
else if ($a['size'] > 10241024) $files[$fkey]['sizetext'] = (ceil($a['size']/(10241024)100)/100) . " Mb";
else $files[$fkey]['sizetext'] = $a['size'] . " bytes";
$files[$fkey]['name'] = $file;
$files[$fkey]['type'] = filetype($fullpath);
$fileNames[$i++] = $fkey;
}
closedir($dh);
} else die ("Cannot open directory: $path");
} else die ("Path is not a directory: $path");
sort($fileNames,SORT_STRING);
$sortedFiles = array();
$i = 0;
foreach($fileNames as $f) $sortedFiles[$i++] = $files[$f];
return $sortedFiles;
}
$files = getFiles("uploads");
foreach ($files as $file) print "<li><a href=\"$file[name]\">$file[name]</a></li>";
?>
im thinking that the error is in the last line where i did an <a href> coz wat it does is redirect it instead ryt? but what is the right tag that i should put there so that the files can be downloaded? thanks