重點:
1、在IE中下載附件之前要清空緩存。
2、中文文件名要用urlencode編碼。
復制代碼 代碼如下:
Header("Pragma: "); //不加的話,IE中會提示目標主機無法訪問
Header("Cache-Control: "); //不加的話,IE中會提示目標主機無法訪問
Header("content-type: $type");
Header("accept-ranges: bytes");
Header("Content-Transfer-Encoding:base64");
Header("accept-length: " . filesize($path_c));
Header("content-disposition: attachment; filename=" .urlencode($filename)); //IE中不用urlencode中文名會出現亂碼
readfile($path_c);
exit;
或
復制代碼 代碼如下:
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.urlencode(basename($file) )); //IE中不用urlencode中文名會出現亂碼
header('Content-Transfer-Encoding: binary'); //二進制傳輸
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); //不加的話,IE中會提示目標主機無法訪問
header('Pragma: public'); //不加的話,IE中會提示目標主機無法訪問
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;