Solved

downloading a file

Posted on 2003-12-04
7
258 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
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…

707 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

20 Experts available now in Live!

Get 1:1 Help Now