?
Solved

downloading a file

Posted on 2003-12-04
7
Medium Priority
?
302 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
[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
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
WordPress Tutorial 3: Plugins, Themes, and Widgets

The three most common changes you will make to your website involve the look (themes), the functionality (plugins), and modular elements (widgets).

In this article we will briefly define each again, and give you directions on how to install them.

 
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 200 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

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
Suggested Courses

777 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