I have following PHP Script for downloading the zip files:
header("Content-length:".filesize($archive_file_name));
header('Content-Type: application/zip'); // ZIP file
header('Content-Disposition: attachment; filename="downloadpackage.zip"');
header('Content-Transfer-Encoding: binary');
readfile($archive_file_name);
exit();
But it doesn't force the download the zip file instead, it shows the lots of unusual characters like below:
PK[ FA # X$D:\\voice_06101243342pm014771957.wav | s] y b CI\\ {2m M' Eibu2\\@B ܋{ 6b# $H,\\@ : Z (q ә Y q , d y O tp$PĽg w} } r֯[7 u "w |o 7/Z ˋ^Z Ң ZTZ\\S|N c X8 c X8 c X8 c X8 c X8 ۲, a oA*=ە do: |ˉ'rb | L2 *^ :q}/ \\ s Z? G [ =ϗ?
I have also placed the below code before the headers function :
if (headers_sent())
{
// HTTP header has already been sent
return false;
}
// clean buffer(s)
while (ob_get_level() > 0)
{
ob_end_clean();
}
This ignore to display those character and zip is also not force to download. I couldn't figure out the problem, please help me, it will be greatly appreciated.
PK[�FA����#�X$D:\voice_06101243342pm014771957.wav�|
�s]�y���b�CI\��{2m��M'�Eibu2\@B��܋{� 6b#
$H,\@��:��Z�(q�����ә���Y��q�����,� ���� d��y��O�tp$PĽg��w}��}
�r֯[7�u�"w���|o�7/Z��ˋ^Z������Ң�ZTZ\S|N����c�X8��c�X8��c�X8��c�X8��c�X8���۲,��a�oA*
=ە���do:��|ˉ'rb�|�L2�*^�:q}/��\�s�Z?��G�[��=ϗ?
This is your zip file.
You are a receiving a zip file and there's nothing wrong, you just need to correct your php processing script because apparently it is processing it as plain text/string.
Note the PK
at the start, zip files start with 'PK` data. Test yourself by opening any zip file with a hex editor.
尝试将此添加到您的标题:
header('Content-Description: File Transfer');
Here is the simple function I use to download files:
function _download ($file_name) {
$src = fopen($this->download_path . $file_name,'r') or die("\n\n ========= Could not download $file_name\n");
$dest = fopen($file_name,'w');
stream_copy_to_stream($src, $dest);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.