Solved

force save dialog box on link

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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
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…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…
Suggested Courses

632 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