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 lammps拉伸应力应变曲线分析
    • ¥15 C++ 头文件/宏冲突问题解决
    • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
    • ¥50 安卓adb backup备份子用户应用数据失败
    • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
    • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
    • ¥30 python代码,帮调试,帮帮忙吧
    • ¥15 #MATLAB仿真#车辆换道路径规划
    • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
    • ¥15 数据可视化Python