Solved

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

Posted on 2007-11-30
4
1,636 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

734 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