• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1648
  • Last Modified:

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

I have pdf links on php pages, but i wanna let user download it instead of opening it directly when clicked. How?
0
jtcy
Asked:
jtcy
  • 2
1 Solution
 
steelseth12Commented:
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
 
jtcyAuthor Commented:
I tot there is a way without using php? I heard smth like just inserting a line in the meta field...
0
 
steelseth12Commented:
Not that i am aware of.
0
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

Featured Post

Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now