5, December 2008

force download of .pdf files - webmaster forum

 
Webdigity webmaster forums
This forum shares its ad revenue with its members!
[ 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

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



« on: Oct 08, 2007, 12:21:50 PM »

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 Visit through proxy

Hope you like it!


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


It's time to use PHP5!


« Reply #1 on: Oct 08, 2007, 01:33:00 PM »

add this header too:

header ("Cache-control: private");


Last blog : Just a better Internet portal provided by Google
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 8272
42619 credits
Members referred : 3



« Reply #2 on: Oct 08, 2007, 01: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 Visit through proxy or twitter Visit through proxy

Last blog : Free Unlimited Bandwith and disk space to good to be true?
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6486
39748 credits
Members referred : 374


It's time to use PHP5!


« Reply #3 on: Oct 08, 2007, 01:42:56 PM »

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

Cheesy


Last blog : Just a better Internet portal provided by Google
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 8272
42619 credits
Members referred : 3



« Reply #4 on: Oct 08, 2007, 01:45:56 PM »

LOL Smiley

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

Last blog : Free Unlimited Bandwith and disk space to good to be true?
Global Moderator
Internet Junkie
*****
Gender: Male
Posts: 1807
9006 credits
Members referred : 6



« Reply #5 on: Oct 08, 2007, 02: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: 6486
39748 credits
Members referred : 374


It's time to use PHP5!


« Reply #6 on: Oct 08, 2007, 02: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


Last blog : Just a better Internet portal provided by Google
Global Moderator
Internet Junkie
*****
Gender: Male
Posts: 1807
9006 credits
Members referred : 6



« Reply #7 on: Oct 08, 2007, 02: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: 8272
42619 credits
Members referred : 3



« Reply #8 on: Oct 08, 2007, 02: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 Visit through proxy or twitter Visit through proxy

Last blog : Free Unlimited Bandwith and disk space to good to be true?
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6486
39748 credits
Members referred : 374


It's time to use PHP5!


« Reply #9 on: Oct 08, 2007, 02:20:16 PM »

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

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


Last blog : Just a better Internet portal provided by Google
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....

Topic sponsors:
Get a permanent link here for $1.99!


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?
Dec 05, 2008, 01:54:45 AM





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!


Forum Statistics
Total Posts: 37.995
Total Topics: 7.685
Total Members: 4.467
Tutorials : 56
Resources : 143
Designs : 220
Latest Member: jschless81

26 Guests, 3 Users online :

10 users online today:



Readers

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