La connaissance à portée de main
Forcer le téléchargement d'un fichier (image, pdf, etc.)
Voici une méthode simple pour forcer le téléchargement d'un fichier tel qu'un image par exemple.
$g_download = (isset($_GET['download'])) ? $_GET['download'] : NULL; if(isset($g_download)){ $filename = ''.$g_download; if (($filename != "") && (file_exists("./" .$filename))) { header('Content-Type: application/force-download; name='. $filename .''); header("Content-Transfer-Encoding: binary"); header('Content-Disposition: attachment; filename='.basename($filename).''); header("Expires: 0"); header("Cache-Control: no-cache, must-revalidate"); header("Pragma: no-cache"); readfile("./".$filename); exit(); } }
Rendu :0.0473 | Mémoire :2.87MB
Accueil | Informations | Top