I have made a simple paypal based shop system for buying files. The procedure at some point (after payment handling) envolves the client getting an email with a link to a php download script with an url embedded download code. This code is valid for several weeks in which the file can be downloaded.
The problem is with the download script itself. Currently it works if I set it up for downloading an mp3 but as soon as I try it for a zip file most machines that tested this got a corrupted unopenable file. The testers experiencing this reported a correct filesize however. Strangely at our office it worked on several computers.
I have tried setting the MIME type (which is currently application/octet-stream) to application/zip and later to application/x-zip-compressed but it does not change anything.
Anyone has some ideas about what could be wrong with my code or maybe server setup?
/* sql quiries to get $product_id and $expired as well as download code verification etc. omitted for this post */
if ($expired != 1)
{
$url = "/serverpath/to/mydomain.tld/shop-files/".$filename;
$mm_type="application/octet-stream";
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public", false);
header("Content-Description: File Transfer");
header("Content-Type: " . $mm_type);
header("Accept-Ranges: bytes");
header('Content-Disposition: attachment; filename="'.basename($url).'"');
header("Content-Transfer-Encoding: binary");
header("Content-Length: " .filesize($url) );
if ($handle = fopen ($url, 'rb'))
{
ob_start();
while(!feof($handle) && connection_status() == 0)
{
print(fread($handle, 1024*8));
set_time_limit(0);
ob_flush();
flush();
}
ob_end_flush();
fclose ($handle);
} else echo "File could not be found";
} else echo "Your downloadlink is expired.";