?
Solved

force save dialog box on link

Posted on 2003-11-24
4
Medium Priority
?
270 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
[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
4 Comments
 
LVL 17

Accepted Solution

by:
dorward earned 400 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 400 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
The viewer will learn how to dynamically set the form action using jQuery.
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.

719 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