doudanma9706 2019-04-12 12:36 采纳率: 100%
浏览 219

失败 - 使用readfile()和filesize()导出数据时,Google Chrome中出现网络错误

I am trying to export data from back-end using a PHP script (download.php).

A folder path issue has been kept me stuck as described in following cases :

Running my site on a sub-domain : softy.foo.com

Script file which executes on user clicking the export button :

download.php (Path : public_html/softy/warehouse/items/download.php)

Case 1 :

Created exportedfiles folder in same location as of download.php i.e. items/exportedfiles - RESULT : file downloads successfully

Case 2 :

Created exportedfiles folder outside items directory - RESULT : file downloads successfully

Case 3 :

Created exportedfiles folder in extreme outside path. i.e. inside public_html folder and I gave full path to readfile() as param - RESULT : file download fails -

The file first proceeds whole downloading in the Chrome downloads but at last when download completes it says :

Failed - Network error

(The above error appears in the Chrome downloads bar along with the size of file ex. : 31 KB)

download.php reads as below :

$FileName = 'itemlist.xls';

$Path = 'exportedfiles/'; //works

$Path = '../exportedfiles/'; //works

$Path = '/mydrive/foo/public_html/softy/exportedfiles/'; //fails



    header("Pragma: public"); // required

    header("Expires: 0");

    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");

    header("Cache-Control: private",false); // required for certain browsers 

    header("Content-Type: application/msexcel");

    header("Content-Disposition: attachment; filename=\"{$FileName}\";" );

    header("Content-Transfer-Encoding: binary");

    header("Content-Length: ".filesize($Path.$FileName)) ;


    readfile($Path."{$FileName}");
  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 对于相关问题的求解与代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料
    • ¥15 使用R语言marginaleffects包进行边际效应图绘制
    • ¥20 usb设备兼容性问题
    • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
    • ¥15 安装svn网络有问题怎么办