Solved

downloading a file

Posted on 2003-12-04
7
289 Views
Last Modified: 2010-04-09
on my web site i will have a link. if the user clicks that link, the user should be able to download the file
i used <a href="XXXXX.xls"> and it worked. but if the file is a jpg or a gif, then it opens in the browser instead of downloading. is there some other way to to this?

i tried using< a href="file:///xxxx.xls">click here to download</a>

but i get an error. am i making some mistake?
0
Comment
Question by:RTKVSNL
7 Comments
 
LVL 33

Expert Comment

by:hongjun
ID: 9874302
Try using absolute path
example
<a href="file:///C:/xxxx.xls">click here to download</a>

hongjun
0
 

Author Comment

by:RTKVSNL
ID: 9874466
i could do that... but on a web site, we always use virtual paths, not drive names
0
 
LVL 33

Expert Comment

by:hongjun
ID: 9874490
then use relative paths like this
< a href="../../xxxx.xls">click here to download</a>

if xxxx.xls is located 2 levels down.

hongjun
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 33

Expert Comment

by:hongjun
ID: 9874502
If you are using ASP, you can do something like this

<a href='<%=Server.MapPath("./yourvirtualpath/xxxx.xls")%>'>click here to download</a>


hongjun
0
 
LVL 9

Accepted Solution

by:
pepsichris earned 50 total points
ID: 9874907
The reason it opens is down to the user's settings on their computer rather than anything you can do.

You have 2 choices:

1) Compress the file into a ZIP file or similar, which will prompt them to download, but they'll have to unzip it once they've downloaded it (www.winzip.com).

2) Instruct them to do a Right click and select "Save Target As".

3) Instruct them to open the picture, right click and "Save Picture As".

4) Take the file extension off the file, and tell them to add it back on once they've downloaded it.

The first answer is generally considered to be the best.

This is one of those unfortunate things that we have no power over, like downloading/opening files from the web without a prompt box coming up.  These things are there for a reason (generally security, sometimes Browser interference).

Also, the XLS file will do the same if they have a plug in for Internet Explorer (or similar) so whatever you do for the pictures, you need to do for that.

Sorry, I know that wasn't the answer you wanted to hear.
0
 

Expert Comment

by:Vrenox
ID: 9874909
Hmm well in my experience sometimes the browser keeps opening the file.
They should always be able to dload the file by right-clicking the link and selecting save as.

Alternatively if you are using Asp you could make it available as a stream:
<a href='downloadimage.asp?strFile=Server.MapPath("./yourvirtualpath/xxxx.yyy")'></a>

downloadimage.asp:
Dim strFileName, strFile, Arr
strFile = Request("strFile")
Arr = Split(strFile, '\')
StrFileName = Arr(UBound(Arr))

Response.ContentType= "application/octet-stream"
 response.addHeader  "content-type", "application/octet-stream"
 response.addHeader  "content-disposition", "attachment; filename="&strFileName
  response.addHeader  "content-transfer-encoding", "binary"
 
   Dim streamobj
   Set streamobj = Server.CreateObject("ADODB.Stream")
   streamobj.Type = adTypeBinary
   streamobj.Open
   streamobj.LoadFromFile strFile
 
   Response.BinaryWrite streamobj.Read
 
   streamobj.Close
   Set streamobj = Nothing

0
 

Author Comment

by:RTKVSNL
ID: 9880145
thank you all for the prompt answers. i will get back after trying out
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

This article discusses four methods for overlaying images in a container on a web page
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …

860 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