Page 1 of 1

corrupted file after download

Posted: Mon Aug 29, 2005 8:32 am
by pad4ever
hi there. i tried to download a pdf using the following script:

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();
		}
i can actually download the file but the file format is corrupted. does anybody know a solution for this please?

pad

Posted: Mon Aug 29, 2005 8:39 am
by n00b Saibot
I don't think the No-Cache headers are required for download & I think they are the main culprit. remove them and then try download again...

Posted: Mon Aug 29, 2005 9:24 am
by pad4ever
nope, that didn't work

Posted: Mon Aug 29, 2005 10:30 am
by feyd
try Content-type, instead of Content-Type