Codice PHP:
echo "<TABLE BORDER=8 WIDTH=40% ALIGN=CENTER BORDER=3>
<TR><TH>Fai clic sui link per scaricare i file</TH></TR>";
# elenco dei contenuti di una cartella con link
$cartella = opendir("upload/".$riga['type']."/");
while ($file = readdir($cartella)) {
$array_file[] =$file;
}
foreach ($array_file as $file) {
echo "<TR><TD><CENTER>";
if ( $file == ".." || $file == ".") {
continue;
}
$dimensioni_file=filesize("upload/".$riga['type']."/".$file);
$dir="upload/".$riga['type']."/".$file;
echo "<a href=\"
download.php?nome_file=$file&dimensioni_file=$dimensioni_file&dir=$dir
\">$file</a>,
";
echo "</TR></TD></CENTER>";
}
Codice PHP:
$nome_file=stripslashes($_GET['nome_file']);
$dimensioni_file=stripslashes($_GET['dimensioni_file']);
$dir=stripslashes($_GET['dir']);
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Type: application/html");
header("Content-Description: File Transfer");
header("Content-type: Application/octet-stream");
header("Content-Disposition: attachment; filename=$nome_file");
header("Content-Description: Download PHP");
header("Content-Length: $dimensioni_file");
readfile($dir);