Entra

View Full Version : [HTML] Download forzato


Gjbob
31-05-2009, 20:56
Ho necessità di fare in modo che cliccando su di un link parta in automatico il download di un file pdf e che questo non venga aperto nel browser. Come posso fare?

Traxsung
31-05-2009, 21:08
potresti usare qualcosa del genere, ma in php:

Codice PHP:

<?php
$file=base64_decode($_GET['file']);

$filename="nomefittiziodelfile";

header("Content-type: application/force-download");
header("Content-Disposition: attachment; filename=$filename");
header("Content-Length: " .filesize($file) );
readfile($file);
?>


mentre per richiamarlo puoi usare questo codice:
echo "<a href=\"download.php?file=".base64_encode($tuofile)."\">scarica</a>";