Solved

downloading a file

Posted on 2003-12-04
7
294 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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. …
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
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…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

726 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