Solved

force save dialog box on link

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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.

706 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now