PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
pad4ever
Forum Newbie
Posts: 9 Joined: Wed Aug 24, 2005 3:58 am
Post
by pad4ever » Mon Aug 29, 2005 8:32 am
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
Last edited by
pad4ever on Mon Aug 29, 2005 8:44 am, edited 3 times in total.
n00b Saibot
DevNet Resident
Posts: 1452 Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:
Post
by n00b Saibot » Mon Aug 29, 2005 8:39 am
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...
pad4ever
Forum Newbie
Posts: 9 Joined: Wed Aug 24, 2005 3:58 am
Post
by pad4ever » Mon Aug 29, 2005 9:24 am
nope, that didn't work
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Aug 29, 2005 10:30 am
try Content-type, instead of Content-Type