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
Solved

force save dialog box on link

Posted on 2003-11-24
4
265 Views
Last Modified: 2010-04-06
i use this code to display a picture link reference that opens an adobe pdf file:

<a href="pdf/paper.pdf">
<img src="buttons/opensave.gif" border="0" width="60" height="50" align="right"></p></a>

i would like the link to force the viewers browser to show the "save / open" dialogue box so that the file doesn't automatically open in the main frame window, and they have a choice to save the file to their desktop.

i also would like to know if there is a way to automatically specify and maybe create a  destination folder named "pdf" where this pdf file will be saved.  a dialogue can ask the user if he would like to create the new folder named "pdf."

thank you.

0
Comment
Question by:Jeter2ss
4 Comments
 
LVL 17

Accepted Solution

by:
dorward earned 100 total points
ID: 9813924
Its usually a good idea to get your HTML straight first...

(1) It isn't a great idea to float images inside a link. I suggest you get rid of the align attribute there.
(2) You have a random end of paragraph in the middle of the link - lose it
(3) You appear to be missing alt text for your image

You can attempt to prompt users to download a file with this technique: http://www.allmyfaqs.com/faq.pl?Download_a_file

You can not specify where on the client to save the file, nor can you create a directory (unless you want to venture down the road of ActiveX controls, no support outside Windows/IE, and lots of scary security warnings for visitors).
0
 
LVL 11

Assisted Solution

by:Zontar
Zontar earned 100 total points
ID: 9814554
To use the Apache webserver trick linked to above, you have to be running Apache and be able to upload .htaccess files, which some hosts won't let you do, and some of them have Apache configured to override any user .htaccess files.

Another way is to link to a file that serves the download file as application/octet-stream:

ASP Code

1. main page:

<a href="download.asp?file=myfile.pdf">DOWNLOAD</a>

2. Source of download.asp:

<%@LANGUAGE="VBSCRIPT"%>
<%
FileName = Request.QueryString("file")
FilePath = Server.MapPath(FileName)

Set FSO = Server.CreateObject("Scripting.FileSystemObject")
Set TSO = FSO.OpenTextFile(FilePath, 1, -2)

Response.ContentType = "application/octet-stream"
Response.AddHeader "content-disposition","attachment; filename=" & FileName

Set Stream = Server.CreateObject("ADODB.Stream")
Stream.Open()
Stream.Type = 1
Stream.LoadFromFile(filePath)
Response.BinaryWrite Stream.Read()
Stream.Close
SET adoStream = Nothing
Response.End
%>

PHP Code

1. Main page:

<a href="download.php?file=myfile.pdf">DOWNLOAD</a>

2. Source of download.php:

<?php
  $filename = $_GET["file"];

  $data = implode("", file(  realpath($filename) ));

  header("Content-Type: application/octet-stream");
  header("Content-Disposition: attachment; filename=$filename");
 
  print($data);
  exit;
?>

Note regarding "</p></a>": It is illegal in HTML to nest a <p> inside a <a>; <a> may contain only text or inline elements.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

809 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