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 71 72 73 74 75 76 77
|
function telechargement($file) {
get_header($file); // équivalent à get_headers()
$Content_Type = explode(':', $_SESSION['head'][2]);
$Content_Type = $Content_Type[1];
$ETag = explode(':', $_SESSION['head'][3]);
$ETag = $ETag[1];
$Content_Length = explode(':', $_SESSION['head'][4]);
$Content_Length = $Content_Length[1];
$Cache_Control = explode(':', $_SESSION['head'][6]);
$Cache_Control = $Cache_Control[1];
$Content_Transfer_Encoding = explode(':', $_SESSION['head'][7]);
$Content_Transfer_Encoding = $Content_Transfer_Encoding[1];
$Accept_Ranges = explode(':', $_SESSION['head'][9]);
$Accept_Ranges = $Accept_Ranges[1];
$size = $Content_Length;
$ETag = $ETag;
$filename = basename($file);
$file_extension = strtolower(substr(strrchr($filename,"."),1));
header('Pragma: public');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: must-revalidate, pre-check=0, post-check=0, max-age=0');
//header("Cache-Control:");
header("Cache-Control: $Cache_Control");
header("Content-Transfer-Encoding: $Content_Transfer_Encoding");
header("Expires: 0");
header("ETag: $ETag");
header("Connection: close");
header("Content-Type: $Content_Type");
if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) {
$iefilename = preg_replace('/\./', '%2e', $filename, substr_count($filename, '.') - 1);
header("Content-Disposition: attachment; filename=\"$iefilename\"");
} else {
header("Content-Disposition: attachment; filename=\"$filename\"");
}
header("Content-Length: $size");
set_time_limit(0);
$fp = fopen("$file","rb");
fseek($fp,$range);
while(!feof($fp)){
print(fread($fp,1024*8));
flush();
ob_flush();
}
fclose($fp);
exit;
}
// utilisation de la fonction
telechargement('url du fichier à télécharger'); |
Partager