Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to make pdf display download dialog in dreamweaver cs3

Posted on 2008-10-14
4
Medium Priority
?
1,240 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 2000 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

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

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

Introduction In this tutorial, I'll explain how to create an animated progress meter in a wireframe prototype developed using Axure RP 7.0 - a leading prototyping tool for designing web sites and software. (For more information about Axure and gett…
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…
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.
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)

722 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