Solved

force save dialog box on link

Posted on 2003-11-24
4
264 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How do you troubleshoot Javascript conflicts on a Bootstrap webpage? 3 441
Examples of Web API, REST web services and SOA 7 236
Select distinct 25 101
Stupid git question 2 88
Article by: Matthew
I am a very big proponent of technology compliance standards and strive to meet such criteria in all of my work. That includes my site, which is 100% XHTML 1.0 compliant as determined by the World Wide Web Consortium. https://www.matthewstevenkel…
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 …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

778 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