Solved

How to make pdf display download dialog in dreamweaver cs3

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Most of the sites are being standardized with W3C Web Standards. W3C provides lot of web standard services to the web. They have the web specification, process and documentation for all the web standards. You can apply HTML, CSS and Accessibility st…
Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…
The purpose of this video is to demonstrate how to set up an RSS Feed on a WordPress Website. This will be demonstrated using a Windows 8 PC. Feedburner will be used for this demonstration. Go to your WordPress login page. This will look like the…

743 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

15 Experts available now in Live!

Get 1:1 Help Now