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 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?
    • ¥15 c++头文件不能识别CDialog