0
在我的項目中,我想下載xxx.zip文件。爲什麼在php下載zip文件時下載文件對話框不能出現
我檢查我的Apache服務器上的文件:
/usr/local/apache2/conf/httpd.conf
這個文件的MIME只有兩個將AddType:
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
這兩種類型不支持壓縮,所以打擊他們我已經補充:
AddType application/zip .zip
然後,我重新啓動httpd服務成功:
直接<?php
$file_name="xxx.zip";
header("Cache-Control: no-cache, must-revalidate");
header("Expires: 0");
header("Content-Disposition: attachment; filename=".basename($file_name));
header("Content-Length:".filesize($file_name));
header("Content-Type:application/zip");
readfile($file_name);
exit;
?>
但不走運,xxx.zip我布勞爾開放內容,並有messcy代碼,而不是下載對話框中我的網站:
service httpd restart
我運行PHP下載
@ӓ�����'t�� :�>]x�I�1W`� ���:�V2g�z����m^ ��Ӄ&8�E���l�:�kؖb��uƘ�z���qD���w�4��p��^&���s�����i/ݽ�mUH�F�x[`�:��#Nr��+|�n�i����ό�U#�}=!j�D�4�}=�'ujc�`��}hl�cr�"��T6���Λb��"/ ���k�vo$%��x/y���Q�����n�����Y�
爲什麼下載文件對話框不能出現?我的linux服務器,瀏覽器和數據庫使用utf8集。誰能幫我 ?我嘗試了其他文件格式,例如:jpeg,png,它們都是直接打開內容而不是下載文件對話框。
你可以告訴我的代碼? – Snow