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

我正在尝试使用PHP脚本(download.php)从后端导出数据。 </ p>

文件夹路径问题一直困扰我,如下列情况所述:</ p>

在子域上运行我的网站:softy.foo。 com </ p>

在用户点击导出按钮时执行的脚本文件:</ p>

  download.php(路径:public_html / softy / warehouse / items  /download.php)

nn

案例1:</ strong> </ p>

创建 exportedfiles </ strong>与download.php相同位置的文件夹,即项目/导出文件</ strong> - 结果:</ strong>文件下载成功</ p>

案例 2:</ strong> </ p>

在项目目录外创建 exportedfiles </ strong>文件夹 - 结果:</ strong>文件成功下载</ p>
\ n

案例3:</ strong> </ p>

在极端外部路径中创建 exportedfiles </ strong>文件夹。 即在public_html文件夹中,我给了readfile()作为参数的完整路径 - 结果:</ strong>文件下载失败</ strong> - </ p>

文件首先 在Chrome下载过程中进行完整下载,但最后在下载完成后说:</ p>


失败 - 网络错误</ p>
</ blockquote>

(Chrome浏览器下载栏中出现上述错误以及文件大小:31 KB)</ p>

download.php </ strong>内容如下: </ p>

  $ FileName ='itemlist.xls'; 

$ Path ='exportedfiles /'; //作品

$ Path ='.. / exportfiles /'; //作品

$ Path ='/ mydrive / foo / public_html / softy / exportedfiles /'; //失败

标题(“Pragma:public”); //必需

标题(“Expires:0”);

标题(“Cache-Control:必须重新验证,post-check = 0,pre-check = 0”);

标题 (“Cache-Control:private”,false); //某些浏览器需要

标题(“Content-Type:application / msexcel”);

标题(“Content-Disposition:attachment; filename = \”{$ FileName} \“;”);

标题(“Content-Transfer-Encoding:binary”);

标题(“Content-Length:”。filesize($ Path。$ FileName));

readfile($ Path) 。“{$ FileName}”);
</ code> </ pre>
</ div>

展开原文

原文

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}");

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐