Solved

How to make pdf display download dialog in dreamweaver cs3

Posted on 2008-10-14
4
1,226 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
[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 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
The purpose of this video is to demonstrate how to Import and export files in WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Click on Too…
The purpose of this video is to demonstrate how to set up basic WordPress SEO. This will be demonstrated using a Windows 8 PC. The plugin used will be WordPress SEO by Yoast. Go to your WordPress login page. This will look like the following: myw…

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