I'm having a strange problem with my force downloading function. It's that everything works out very nice using Firefox but in explorer I just get the "Save as" prompt and after that everything dies and an error msg is displayed.
This is the code I'm using for my download function as a part of my complete filemanager.
As you see all kinds of file-types could be downloaded.
// FORCE DOWNLOAD FROM FILEMANAGER
$fileId = $_GET['fileId'];
$path = "/server/projectfiles/project_";
if ($_GET['action'] == "download") {
// Get file-data
$query = "SELECT projectId,physicalName,virtualName FROM filemanagerTbl WHERE id=". $fileId;
$rs = mysql_query($query) or die(mysql_error());
if (mysql_num_rows($rs) != 0) {
$path .= mysql_result($rs, 0, 'projectId') ."/";
// Get content-type
$exp = explode(".", mysql_result($rs, 0, 'virtualName'));
$fileExt = "." . $exp[count($exp)-1];
switch($fileExt) {
case ".jpg" : $cType = "image/jpeg"; break;
case ".gif" : $cType = "image/gif"; break;
case ".png" : $cType = "image/png"; break;
case ".asf" : $cType = "video/x-ms-asf"; break;
case ".avi" : $cType = "video/avi"; break;
case ".doc" : $cType = "application/msword"; break;
case ".zip" : $cType = "application/zip"; break;
case ".xls" : $cType = "application/vnd.ms-excel"; break;
case ".wav" : $cType = "audio/wav"; break;
case ".mp3" : $cType = "audio/mpeg3"; break;
case ".mpg" : $cType = "video/mpeg"; break;
case ".mpeg" : $cType = "video/mpeg"; break;
case ".rtf" : $cType = "application/rtf"; break;
case ".pdf" : $cType = "application/pdf"; break;
case ".html" : $cType = "text/html"; break;
default : $cType = "application/octet-stream";
}
// Download
Header("Content-type: ". $cType);
Header('Content-Disposition: attachment; filename="'. mysql_result($rs, 0, 'virtualName') ."\"\n");
Header("Content-transfer-encoding: binary");
Header("Content-length: ". filesize($path . mysql_result($rs, 0, 'physicalName')). "\n");
readfile($path . mysql_result($rs, 0, 'physicalName'));
}
Somebody help me...!