28, May 2012

force download of .pdf files - webmaster forum

 
Webdigity webmaster forums
[ Home | Help | Search | Forum's Shop | Archive | Login | Register | Webmaster Directory ]
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: force download of .pdf files
« previous next »
Pages: [1] Print
Instabuck - The easy way to sell digital products online

Author Topic: force download of .pdf files  (Read 2100 times)
Global Moderator
Internet Junkie
*****
Gender: Male
Posts: 1807
9006 credits
Members referred : 6



« on: Oct 08, 2007, 11:21:50 am »

After getting annoyed a few too many times after opening .pdf file in the browser window I looked into forcing the download so the 'save as' window pops up after clicking on a .pdf link (like it does when clicking on a link to a .zip file)

I found a way to force the download and added a counter as well. You can see the complete script on my php tutorial site here: force .pdf download

Hope you like it!


Last blog : Are You Stumbling Yet?
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #1 on: Oct 08, 2007, 12:33:00 pm »

add this header too:

header ("Cache-control: private");

I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #2 on: Oct 08, 2007, 12:37:19 pm »

The best is to use this :

header("Cache-Control: public"); 
header("Pragma: public"); 
header("Content-Description: File Transfer"); 
header("Content-type: application/octet-stream");
header("Content-disposition: attachment; filename=$fnam");
header("Content-Transfer-Encoding: binary");
?>


The Content-type: application/octet-stream will make the file downloaded no matter the file type or extension.

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #3 on: Oct 08, 2007, 12:42:56 pm »

and at last this header:
header("Best-webmaster-forum: Webdigity");

Cheesy

I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #4 on: Oct 08, 2007, 12:45:56 pm »

LOL Smiley

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
Global Moderator
Internet Junkie
*****
Gender: Male
Posts: 1807
9006 credits
Members referred : 6



« Reply #5 on: Oct 08, 2007, 01:08:09 pm »

That last header isn't working Olaf. I've send an e-mail to php.net to ask how to use that header, since it isn't in the php manual. They must have missed it somehow...


Last blog : Are You Stumbling Yet?
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #6 on: Oct 08, 2007, 01:16:30 pm »

That last header isn't working Olaf. I've send an e-mail to php.net to ask how to use that header, since it isn't in the php manual. They must have missed it somehow...

Nico, don't send this to php.net, headers are coordinated by the W3C

Smiley

Global Moderator
Internet Junkie
*****
Gender: Male
Posts: 1807
9006 credits
Members referred : 6



« Reply #7 on: Oct 08, 2007, 01:17:23 pm »

I already send it, I'll just send a copy of the mail to W3C then Grin


Last blog : Are You Stumbling Yet?
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #8 on: Oct 08, 2007, 01:18:27 pm »

Hehe, we will be the first site with each owns headers Smiley

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #9 on: Oct 08, 2007, 01:20:16 pm »

Hehe, we will be the first site with each owns headers Smiley

right a new standard:
header("Personal-Header: Olaf Lederer");

Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=7201
Tags : php pdf download force download tutorial Bookmark this thread : Digg Del.icio.us Dzone more....

Pages: [1] Print 
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: force download of .pdf files
« previous next »
Jump to:
User Area
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 28, 2012, 09:30:51 pm





Login with username, password and session length

Donate to our community, and get a permanent link back to your site!

Donate to our community, and get a permanent link back to your site!






Web Design Gallery · Whois Lookup · Pagerank · Tag Browsing · Lo-fi version · Syndication · Webmaster forum history · Advertise
Developed by HumanWorks © 2005 - 2012 Webdigity webmaster community · sublime directory
Webdigity Webmaster Forums | Powered by SMF 1.0.12. © 2001-2005, Lewis Media. All Rights Reserved.