1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| switch($row['ExtFile']){
case('zip') : $Mime ='multipart/x-zip';
break;
case('pdf') : $Mime ='application/pdf';
break;
}
//
// Constantes de configuration
//
define('CFG_SYSTEM_FILENAME', trim($row['PathFile'])); // Nom du fichier pour le système
define('CFG_SEND_FILENAME', trim($row['NomFile']).'.'.trim($row['ExtFile'])); // Nom du ficher pour le navigateur
//
// Constantes à ne pas modifier
//
define('CFG_FILESIZE', filesize(CFG_SYSTEM_FILENAME));
define('CFG_FILE_MD5', md5_file($row['PathFile']));
define('CFG_DATE_FORMAT', 'D, d M Y H:i:s');
//
// Quelques éléments nécessaires
//
error_reporting(0);
ini_set('zlib.output_compression', 0);
// Gestion du cache
//
header('Pragma: public');
header('Last-Modified: '.gmdate(CFG_DATE_FORMAT).' GMT');
header('Cache-Control: must-revalidate, pre-check=0, post-check=0, max-age=0');
//
// Informations sur le contenu à envoyer
//
header('Content-Tranfer-Encoding: none');
header('Content-Length: '.CFG_FILESIZE);
header('Content-MD5: '.base64_encode(CFG_FILE_MD5));
header('Content-Type: application/octetstream; name="'.CFG_SEND_FILENAME.'"');
header('Content-Type: '.$Mime.'; name="'.CFG_SEND_FILENAME.'"');
header('Content-Disposition: attachment; filename="'.CFG_SEND_FILENAME.'"');
//
// Informations sur la réponse HTTP elle-même
//
header('Date: '.gmdate(CFG_DATE_FORMAT, time()).' GMT');
header('Expires: '.gmdate(CFG_DATE_FORMAT, time()+1).' GMT');
header('Last-Modified: '.gmdate(CFG_DATE_FORMAT, time()).' GMT');
//
// Envoi du fichier
readfile(CFG_SYSTEM_FILENAME); |
Partager