PHP IIS 下载文件时出现问题,表示文件已损坏

发布于 2024-08-29 11:13:32 字数 794 浏览 3 评论 0原文

我正在 IIS 6 上使用 mssql 运行 PHP。我已经通过 php 脚本将文件上传到我的网络服务器。检查服务器上的文件后,文件正常并且没有损坏。但是,当我的网站上有一个链接尝试下载该文件时,它说该文件已损坏。

我知道该文件没有损坏,因为如果我查看服务器上的文件,我可以完美地查看它。

这似乎是一个常见问题,因为这里发布了类似的问题:

http:// /www.bigresource.com/Tracker/Track-php-1pAakBhT/

任何帮助将不胜感激。

谢谢,

M

我的下载代码如下:

$filesize = $rows->filesize;
$filepath = $rows->filepath;

header("Content-Disposition: attachment; filename=$filename");
header("Content-length: $filesize");
header("Content-type: application/pdf");
header("Cache-control: must-revalidate");
header("Content-Description: PHP Generated Data");

readfile($filepath);

已修复:“只需确保之前和/或之后没有空格或新闻行”

I am running PHP on IIS 6 with mssql. I have uploaded a file to my webserver through a php script. Upon checking the file on the server the file is ok and not corrupt. However, when i then have a link on my website to try and download the file, it says the file is corrupt.

I know the file isnt corrupt as i can view it perfectly if i look at the file on the server.

Is seems like this is a common problem as a similar problem was posted here:

http://www.bigresource.com/Tracker/Track-php-1pAakBhT/

Any help would be much appreciated.

Thanks,

M

My download code is as follows:

$filesize = $rows->filesize;
$filepath = $rows->filepath;

header("Content-Disposition: attachment; filename=$filename");
header("Content-length: $filesize");
header("Content-type: application/pdf");
header("Cache-control: must-revalidate");
header("Content-Description: PHP Generated Data");

readfile($filepath);

FIXED: "just make sure you don't have spaces or news lines before and/or after "

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

萌面超妹 2024-09-05 11:13:32

我敢打赌*有啤酒**,PHP 错误消息会破坏本来很好的文件下载。

使用记事本查看下载文件的源代码。

* 奖品只能在德国科隆兑换。必须年满 18 岁才能参加。

** 1 Kölsch 按当地平均价格计算。

I'll bet* a beer** that there are PHP error messages corrupting the otherwise fine file download.

Take a look into the downloaded file's source code using Notepad.

* Prize can be redeemed in Cologne, Germany, only. Must be over 18 to participate.

** 1 Kölsch at average local rate.

独享拥抱 2024-09-05 11:13:32

如果您使用 IE 下载 PDF,您可以尝试:

header("Cache-Control: private");
header("Content-Transfer-Encoding: binary");

这对我们有用:p。

If you're downloading PDFs with IE you might try :

header("Cache-Control: private");
header("Content-Transfer-Encoding: binary");

That worked for us :p.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文