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
| <?php
if(isset($_GET['Fichier_a_telecharger']) && ($_GET['Fichier_a_telecharger'] !='')){
$Fichier_a_telecharger = $_GET['Fichier_a_telecharger'];
}else{
$Fichier_a_telecharger = '';
}
if(isset($_GET['chemin']) && ($_GET['chemin'] !='')){
$chemin = $_GET['chemin'];
}else{
$chemin = '';
}
if($Fichier_a_telecharger !='' && $chemin !=''){
// on essaie de reconnaitre l'extension pour que le téléchargement corresponde
// au type de fichier afin d'éviter les erreurs de corruptions
switch(strrchr(basename($Fichier_a_telecharger), "."))
{
case ".gz": $type = "application/x-gzip"; break;
case ".tgz": $type = "application/x-gzip"; break;
case ".zip": $type = "application/zip"; break;
case ".pdf": $type = "application/pdf"; break;
case ".png": $type = "image/png"; break;
case ".gif": $type = "image/gif"; break;
case ".jpg": $type = "image/jpeg"; break;
case ".txt": $type = "text/plain"; break;
case ".htm": $type = "text/html"; break;
case ".html": $type = "text/html"; break;
default: $type = "application/octet-stream"; break;
}
header("Content-disposition: attachment; filename=$Fichier_a_telecharger");
header("Content-Type: application/force-download");
header("Content-Transfer-Encoding: $type\n"); // Surtout ne pas enlever le \n
header("Content-Length: ".filesize($chemin . $Fichier_a_telecharger));
header("Pragma: no-cache");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0, public");
header("Expires: 0");
readfile($chemin . $Fichier_a_telecharger);
}
?> |
Partager