gpt4 book ai didi

PHP强制下载显示网络错误

转载 作者:行者123 更新时间:2023-12-04 02:09:22 25 4
gpt4 key购买 nike

我尝试使用 PHP 强制下载来下载文档,我使用了以下代码

 header("Content-Type: application/octet-stream");
header("Content-Transfer-Encoding: Binary");

header("Content-Length: ".filesize($path) ."\"");

header("Content-Disposition: attachment; filename=\"".basename($path)."\"");

header("Expires: 0");

header("Cache-Control: no-cache, must-revalidate");

header("Pragma: no-cache");
ob_clean();
flush();

readfile($path);

exit;

但是当我运行脚本时,它只显示下载开始...并在 chrome 中显示“网络错误”,当我检查网络控制台时,它显示类似这样的内容

Request URL:http://websddress.com/presse/index.php?option=com_presse&task=viewDoc&id=2578&lg=FR
Request Method:GET
Status Code:200 OK
Request Headersview source
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-GB,en-US;q=0.8,en;q=0.6
Connection:keep-alive
Cookie:__utma=139058359.696419680.1380560986.1380711878.1380731571.5; __utmz=139058359.1380560986.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); 58a32855c678fbf6131983dab57747c9=uv0bipblgn8bd3diqbd52dn9g1; 64cf32705845a188b511407ba5bcd3d6=edbgk8jtalamqnininr89qb327
Host:5.135.115.74
Referer:http:webaddress.com/presse/index.php?option=com_presse&task=viewDocs&secid=787&lg=fr
User-Agent:Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36
Query String Parametersview sourceview URL encoded
option:com_presse
task:viewDoc
id:2578
lg:FR
Response Headersview source
Cache-Control:no-cache, must-revalidate
Content-Disposition:attachment; filename="Advanced_Fair_-_Grohe_september_doc_FR_2578.pdf"
Content-Length:"
Content-Transfer-Encoding:Binary
Content-Type:application/octet-stream
Date:Thu, 21 Nov 2013 15:49:29 GMT
Expires:0
P3P:CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"
Pragma:no-cache
Server:Microsoft-IIS/7.5
X-Powered-By:ASP.NET
X-Powered-By:PHP/5.3.23

最佳答案

这个:

header("Content-Length: ".filesize($path) ."\"");

标题中的输出是这样的:

Content-Length:"

替换为:

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

并修复 $path,这也是不正确的,因为它返回 null(或 false)。

输出应该是这样的:

Content-Length: 10032219

此外,PDF 的正确 mime 类型是:

 Content-Type: application/pdf

关于PHP强制下载显示网络错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20126357/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com