corrupted file after download
Posted: Mon Aug 29, 2005 8:32 am
hi there. i tried to download a pdf using the following script:
i can actually download the file but the file format is corrupted. does anybody know a solution for this please?
pad
Code: Select all
if($_GET['dl']==1) {
$filename = "pdf/pdf".$_GET['productid'].".pdf";
$file_extension = strtolower(substr(strrchr($filename,"."),1));
switch( $file_extension )
{
case "pdf": $ctype="application/pdf"; 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);
header("Content-Type: $ctype");
header("Content-Disposition: attachment; filename=\"".basename($filename)."\";" );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($filename));
readfile("$filename");
exit();
}pad