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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
$file = ".... chemin de ton fichier";
function dl_file($file)
{
if (!is_file($file))
{
die("<b>404 Fichier non trouvé!</b>");
}
$len = filesize($file);
$filename = basename($file);
$file_extension = strtolower(substr(strrchr($filename,"."),1));
$header=="Content-disposition: inline; filename=".$filename.";";
switch( $file_extension )
{
case "pdf": $ctype="application/pdf"; break;
case "exe": $ctype="application/octet-stream"; break;
case "zip": $ctype="application/zip"; break;
case "doc": $ctype="application/msword"; break;
case "xls": $ctype="application/vnd.ms-excel"; break;
case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
case "gif": $ctype="image/gif"; break;
case "png": $ctype="image/png"; break;
case "jpeg":
case "jpg": $ctype="image/jpg"; break;
case "mp3": $ctype="audio/mpeg"; break;
case "wav": $ctype="audio/x-wav"; break;
case "mpeg":
case "mpg":
case "mpe": $ctype="video/mpeg"; break;
case "mov": $ctype="video/quicktime"; break;
case "avi": $ctype="video/x-msvideo"; break;
case "txt": $ctype="application/msword"; break;
downloaded (sensitive stuff, like php files)
case "php":
case "htm":
case "Html":
die("<b>Cannot be used for ". $file_extension ." files!</b>"); break;
default:
$ctype="application/force-download";
$header="Content-Disposition: attachment; filename=".$filename. ";";
}
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Type: $ctype");
filename=".$filename.";";
header($header);
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".$len);
@readfile($file);
}
dl_file($file); |