首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >PHP下载在输出屏幕上显示gibbrish

PHP下载在输出屏幕上显示gibbrish
EN

Stack Overflow用户
提问于 2014-06-14 04:03:39
回答 1查看 98关注 0票数 1

PHP的文件下载代码在屏幕上显示gibbrish,而不是打开保存/打开窗口。我从PHP.net站点http://www.php.net//manual/en/function.readfile.php获得了这段代码,请帮助我应该做什么?

$file1 = 'DataUpload.xls‘

代码语言:javascript
运行
复制
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��� ��� ��+���/�“��������

EN

回答 1

Stack Overflow用户

发布于 2014-06-14 04:27:27

代码语言:javascript
运行
复制
$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();
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24216469

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档