PHP的文件下载代码在屏幕上显示gibbrish,而不是打开保存/打开窗口。我从PHP.net站点http://www.php.net//manual/en/function.readfile.php获得了这段代码,请帮助我应该做什么?
$file1 = 'DataUpload.xls‘
if (file_exists($file1)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file1));
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file1));
ob_clean();
flush();
readfile($file1);
exit;
}屏幕上的输出:��������>������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������f2�ɀ����\p B�a�=���=��G9!8x@�“��1���杯1���Calibri1���Calibri1���Calibri1����Arial1���Calibri1���校准1���校准1�4��校准1���Calibri1�>��Calibri1�?��Calibri1�4��Calibri1�4��Calibri1���杯1���杯1���杯1���杯1���杯1���杯“$”###0_);(“$ #,##0)!”$#,##0_);Red“$”#,##0.00_);("$"#,##0.00)‘“$”#,##0.00_);Red7*2_("$"* #,##0_);("$"* (#,##0);($“*”-);(@))(* #,##0_);(* (#,##0);(*“-”);(@);(“$”* #,##0.00_);("$"* (#,##0.00);(“$*”-??);(@)6+1(* #,##0.00_);(* (#,##0.00);(*“-”?);(@_)������.�/���.�‘�1�’�‘���������#������>�‘�1�’�5�!��ff�����ff����+�������)�,�*�%���P�P��� ��� ��+���/�“��������
发布于 2014-06-14 04:27:27
$file1 = 'DataUpload.xls';
header('Pragma: public'); // required
header('Expires: 0'); // no cache
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: private',false);
header('Content-Type:application/force-download');
header('Content-Disposition: attachment; filename="'.basename($file1).'"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: '.filesize($file1)); // provide file size
header('Connection: close');
readfile($file1);
exit();https://stackoverflow.com/questions/24216469
复制相似问题