How to prompt to save pdf instead of opening it in browser?

Posted on 2007-11-30
Medium Priority
Last Modified: 2013-12-12
I have pdf links on php pages, but i wanna let user download it instead of opening it directly when clicked. How?
Question by:jtcy
  • 2
LVL 20

Accepted Solution

steelseth12 earned 2000 total points
ID: 20380775
You will need to use php to force download.
Instead of pointing the user to the pdf , point them to a php file with the following code
    $path = "path/to/file";
	$file = "file.pdf";
	header ("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Length: ' . filesize($path.DIRECTORY_SEPARATOR.$file));
    header('Content-Disposition: attachment; filename=' . $file);

Open in new window


Author Comment

ID: 20380855
I tot there is a way without using php? I heard smth like just inserting a line in the meta field...
LVL 20

Expert Comment

ID: 20380867
Not that i am aware of.

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

619 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question