Dynamic Zip file fails with jpg image
Hi,
I have a weird problem with a web page, Hoping somebody can help.
I use php to create a zip file on the server when the page is requested (can latter be opened fine with winzip) the contents is read back into a variable and is directly sent back to the client after setting the content headers, and will be downloaded by the browser as a zip file. All works fine so far and the received zip file opens fine in winzip
However, if the zip file happens to contain a jpg file of above a certain size, aprox 10-12kb then the received file is corrupt and wont open (the file on the server however is still ok to open with winzip).
I dont think size is an issue as it works fine with large files eg 60Mb, small jpg files eg less than 10kb work fine also. It only seems to affect jpg files over 10-25kb and ONLY when sent directly to the client.
There are obvious work arrounds to this eg. give a link to the zip file on the server but I would rather fix the problem than work arround it.
Here is the code:
header("Content-Type: application/octet-stream zip\r\n");
header("Content-Length: ".filesize('c:\zipfile.zip')."\r\n");
header("Content-Disposition: attachment;
filename=".$clientFileName."\r\n\r\n");
$temp = fopen('c:\zipfile.zip','rb');
$contents = fread($temp,filesize($temp));
print ($contents);
setting application/zip does not work either :-(
Any sugestions apreciated.
|