萬盛學電腦網

 萬盛學電腦網 >> 網絡編程 >> php編程 >> PHP IE中下載附件問題解決方法

PHP IE中下載附件問題解決方法

 在IE中下載附件之前要清空緩存、中文文件名要用urlencode編碼,下面有個不錯的示例,需要的朋友可以參考下

重點:    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;   
copyright © 萬盛學電腦網 all rights reserved