Solved

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

Posted on 2007-11-30
4
1,632 Views
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?
0
Comment
Question by:jtcy
  • 2
4 Comments
 
LVL 17

Expert Comment

by:Shanmuga Sundaram
ID: 20380774
0
 
LVL 20

Accepted Solution

by:
steelseth12 earned 500 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);

    readfile($path.DIRECTORY_SEPARATOR.$file); 

	

	?>

Open in new window

0
 

Author Comment

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

Expert Comment

by:steelseth12
ID: 20380867
Not that i am aware of.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now