Nella pagina del download
Codice PHP:
if(is_file($_GET['file']) && substr($_GET['file'],-3)=='pdf'){
header("Content-type: Application/octet-stream");
header("Content-Disposition: attachment; filename={$_GET['file']}");
header("Content-Description: Download PHP");
readfile($_GET['file']);
}else header("Location: index.php");
Nella pagina dove stampi files
Codice PHP:
$dir='img/';
$estensioni = array('jpg','gif','pdf');
$cartella = scandir($dir);
foreach($cartella as $file)
if (in_array(substr($file,-3),$estensioni))
echo (substr($file,-3)=='pdf') ? "Download: <a href=\"download.php?file=$dir$file\" target='_blank'>$file</a>
" : "File: <a href=\"$dir/$file\" target='_blank'>$file</a>
";
E dovrebbe andarti