Solved

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

Posted on 2007-11-30
4
1,634 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 Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

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

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

839 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