Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

downloading a file

Posted on 2003-12-04
7
Medium Priority
?
308 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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.
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 to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
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…

618 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