Solved

How to make pdf display download dialog in dreamweaver cs3

Posted on 2008-10-14
4
1,222 Views
Last Modified: 2012-05-05
When I link to pdf file using dreamweaver cs3, the pdf file automatically opens in browser.
But I want the download dialog to be display instead of it opening automatically .
0
Comment
Question by:ee020165
  • 2
4 Comments
 
LVL 14

Accepted Solution

by:
yessirnosir earned 500 total points
ID: 22712007
There are many links for "force pdf download".  I couldn't get any of the Javascript methods to work, but with a combination of tips from two php-based methods it seems to work well.
I used the force-download.php script from here:
http://elouai.com/force-download.php
And I modified my .htaccess with tips from here:
http://www.phpinclude.net/scripts.php?T=19.  

The nice thing about the .htaccess mod is that it only applies to pdf file in a particular folder on your server, in this case called "downloads".  So a pdf anywhere else on your server will open in the normal way, but a pdf in the downloads folder will be saved to disk.

Have included both the script and the .htaccess below.

<?php   /* save this as force-download.php */
$filename = $_GET['file'];
 
// required for IE, otherwise Content-disposition is ignored
if(ini_get('zlib.output_compression'))
  ini_set('zlib.output_compression', 'Off');
 
// addition by Jorg Weske
$file_extension = strtolower(substr(strrchr($filename,"."),1));
 
if( $filename == "" ) 
{
  echo "<html><title>eLouai's Download Script</title><body>ERROR: download file NOT SPECIFIED. USE force-download.php?file=filepath</body></html>";
  exit;
} elseif ( ! file_exists( $filename ) ) 
{
  echo "<html><title>eLouai's Download Script</title><body>ERROR: File not found. USE force-download.php?file=filepath</body></html>";
  exit;
};
switch( $file_extension )
{
  case "pdf": $ctype="application/pdf"; break;
  case "exe": $ctype="application/octet-stream"; break;
  case "zip": $ctype="application/zip"; break;
  case "doc": $ctype="application/msword"; break;
  case "xls": $ctype="application/vnd.ms-excel"; break;
  case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
  case "gif": $ctype="image/gif"; break;
  case "png": $ctype="image/png"; break;
  case "jpeg":
  case "jpg": $ctype="image/jpg"; break;
  default: $ctype="application/force-download";
}
header("Pragma: public"); // required
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false); // required for certain browsers 
header("Content-Type: $ctype");
// change, added quotes to allow spaces in filenames, by Rajkumar Singh
header("Content-Disposition: attachment; filename=\"".basename($filename)."\";" );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($filename));
readfile("$filename");
exit();
 
?>
 
Add this to .htaccess:
RewriteEngine on
RewriteBase /
RewriteRule ^downloads/([A-Za-z0-9_]*).pdf /downloads/force-download.php?file=$1.pdf
 

Open in new window

0
 

Author Comment

by:ee020165
ID: 22712268
Thanks for the reply. I think, its close to the answer already. Only that, where can I find this .htaccess in dreamweaver ?
0
 
LVL 14

Expert Comment

by:yessirnosir
ID: 22712414
.htaccess is a file that you put on your server.  It is just a simple text file that you can edit with notepad or other text editor.  It is a method of setting additional configuration options for your server.  see:  http://httpd.apache.org/docs/1.3/howto/htaccess.html.

If you don't have an .htaccess file already, then just create a new one with those three lines I gave you, save as .htaccess, and upload to your server.  Be careful though, since errors in .htaccess can crash your site.  So if downtime on your site would be a problem, you should probably test any changes on a test server.  Personally, I use the XAMPP package on my Windows PC to provide a test server, and that is really helpful.
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 22725894
Just to add an FYI to this:

DW CS3 sometimes masks local copies of the .htaccess file, just like the server does.  So if you create the file in Dreamweaver, you will be able to see it locally but sometimes after closing and reopening DW, the file "disappears"

It's still there, you just need to use a regular file browser to find it and Notepad to edit it.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
The viewer will learn how to count occurrences of each item in an array.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

813 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

12 Experts available now in Live!

Get 1:1 Help Now