forcer téléchargement sur un lien
Publié : 23 févr. 2005, 10:42
bonjour à tous,
j'ai essayer de forcer le telechargement sur des liens pointant vers des documents Office, mais rien ne marche, ca me telecharge mon script
mon lien
"mon" script
j'ai zoné les différents forum mais aucune soluce ne marche
à l'aide
j'ai essayer de forcer le telechargement sur des liens pointant vers des documents Office, mais rien ne marche, ca me telecharge mon script

mon lien
Code : Tout sélectionner
<?php
// Test du téléchargement d'un fichier avec reconnaissance du type de fichier
echo "<a href=\"telecharger.php?file=texte.txt&chemin=\">Télécharger</a>";
?>
Code : Tout sélectionner
<?php
// 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($file), ".")) {
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.$file));
header("Pragma: no-cache");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0, public");
header("Expires: 0");
readfile($chemin.$file);
?>
j'ai zoné les différents forum mais aucune soluce ne marche
à l'aide