Ive written a download application in PHP that can handle any type of file...however I had some problems first with some file types (gifs ect) displaying and not downloading and then with the browser download the page and not the file.
using these DevShed forums I managed to find examples and managed to get the code below which gets around BOTH of the problems i was facing but now when someone goes to download files they end up being corrupted (all file types except images)
Any ideas why this is the case?
function force_download($path)
{
global $HTTP_USER_AGENT;
$file=basename($path);
header("Content-Type: application/octet-stream");
header("Content-Type: application/force-download");
header("Content-Length: $size");
// Required to get around the MSIE 5.5 Bug of downloading filname.php
if(preg_match("/MSIE 5.5/", $HTTP_USER_AGENT))
{
header("Content-Disposition: filename=\"$file\"");
} else
{
header("Content-Disposition: attachment;filename=$file");
}
//header("Content-Transfer-Encoding: binary");
$fh = fopen($path, "r");
fpassthru($fh);
}