Solved

How to make pdf display download dialog in dreamweaver cs3

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

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…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

919 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