开发者

PHP IIS problems downloading file says it is corrupt

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 corrup开发者_开发百科t. 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 "


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.


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

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

That worked for us :p.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜