views:

106

answers:

2

Hi,

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 "

+1  A: 

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.

Pekka
Ooo - if it's an IE issue then you'll need to pay up!
zaf
@zaf: But one Kölsch more or less... that's considered the "usual evaporation effect" for someone living in Cologne ;-)
VolkerK
@Volker you truly understand the soul of this city. :)
Pekka
+1  A: 

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

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

That worked for us :p.

wimvds