Hello,

I am trying to download file through php.
My script is

PHP Code:
$filename $_GET['file'];
$file "uploads/" $filename;
$file_extension strtolower(substr(strrchr($file,"."),1));        
switch( 
$file_extension )
{
    case 
"pdf"$ctype="application/pdf"; break;
    case 
"zip"$ctype="application/zip"; break;
    case 
"doc"$ctype="application/msword"; break;
    case 
"xls"$ctype="application/vnd.ms-excel"; break;
    case 
"ppt"$ctype="application/vnd.ms-powerpoint"; break;
    case 
"gif"$ctype="image/gif"; break;
    case 
"png"$ctype="image/png"; break;
    case 
"jpeg":
    case 
"jpg"$ctype="image/jpeg"; break;
    case 
"wav":
    case 
"mp3"$ctype="application/iTunes"; break;
    default: 
$ctype="application/force-download";
}
header("Pragma: public"); // required
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false); // required for certain browsers 
header("Content-Type: $ctype");
header("Content-Disposition: attachment; filename=\"".basename($file)."\";" );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($file));
readfile("$file");
exit(); 

The above script opens the dialog box but
I get a "File Conversion" dialog box with three options "Windows Default", "MS-DOS", and "Other encoding" . "Windows Default" is always set when this dialog comes up.

When I press "Ok" in this dialog, word doc. opens - and the body of the document contains garbage characters before and after the body of the document.


What is wrong with the code?
Please guide me.