Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Downloading Buttons 1

Status
Not open for further replies.

Chipsman

Programmer
May 26, 2005
44
GB
Hi,

I am creating a site using Dreamweaver MX and I would like to make working download buttons.

What I do for the moment is creating a rollover picture of a button that has a link to a file.

The files I want the user to be able to download are often *.pdf, *.doc, *.eps, *.tif, *.jpg.

The link is just a link to the file, however two different things happen:
- If the link leads to a *.eps or a *.tif file, then a window opens and I have the usual downloading options ("Open", "save", "cancel")
- If the link leads to a *.doc, *.pdf, or *.jpg file, then the file opens automatically in internet explorer. No downloading options.

Can you tell me what I am doing wrong? Cause it's the exact same code for both, and I would like to get the downloading options ("Open", "save", "cancel") for all the files.

Thank you so much for your help


 
The problem is that IE can open .doc(etc) files and therefore doesn't need the user to download them. The easiest option is to put the files in a zip folder, this will force the Open/Save dialogue.

I do have some script somewhere that does force the download but cant remember where it is at the moment.

Cheech

[Peace][Pipe]
 
Thanks for your advice Cheech, the zip folder trick is actually what I found as a temporary solution... but there is more than 500 different files to zip, it's very time consuming.

If you find your script (or if someone else has some) I'd be very interested to have a look at it.

Cheers mate ;-)
 
Doesnt appear to be MX 2004 compatible. But I think that is where i got my script from. But what I fave done is created a downoad.asp page and instead of creating a page per file I just add the file name to the URL in any link and grab it on the download page

so thanks to Tom Muck for the original script, heres my version
Code:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
strFile = request.QueryString("file")
strOne = "attachment; filename=" & strFile
strTwo = "docs/" & strFile
Response.Buffer=true
On Error Resume Next
'Create a stream object
Dim tfm_downloadStream
Set tfm_downloadStream = Server.CreateObject("ADODB.Stream")
tfm_downloadStream.Type = 1
tfm_downloadStream.Open
tfm_downloadStream.LoadFromFile Server.Mappath(strTwo)
If Err.number = 0 Then
  Response.Clear
  Response.ContentType = "application/octet-stream"
  Response.AddHeader "Content-Disposition", strOne
  Response.AddHeader "Content-Transfer-Encoding","binary"
  Response.BinaryWrite tfm_downloadStream.Read
  tfm_downloadStream.Close
  Set tfm_downloadStream = Nothing
  Response.End()
Else
  tfm_downloadStream.Close
  Set tfm_downloadStream = Nothing  
  Response.Redirect("oops.asp")
End If 
%>

Cheech

[Peace][Pipe]
 
Hi,

I want to make a Download button for each of my files.
I would like that when the user clicks on it, he get the usual 3 options ("Open","Save", "Cancel") that are usual with Windows.

The problem is that when it's a *.eps file, it does it automatically, but if it's a *.doc or *.jpg file, it opens it in IE...

To force the download, Cheech here told me that I could put the file in a Zip folder. This really force the download BUT it works with Windows versions older than XP. When the user uses XP, the options don't appear and the user get access to the file itself and can alter it...

Does anyone know how I can force the options to appear even when using XP?

Thanks
Chips
 
yes save the script above as download.asp, line 4 points the script at the folder your docs are kept. Just change that to wherever you keep your files and then when you want a download link you can just use a link as below
Code:
<a href="download.asp?file=somefile.doc">Link text</a>
If you wanted to get real funky you could do this using File.SystemObject to read the folder contents and just loop through them, this way you can just darg and drop new files to make them appear/disappear. But we will cover that in another lesson ;-)

Cheech

[Peace][Pipe]
 
Thanks Cheech for your answers, but I didn't manage to change the right things .... or it doesn't work.

Could you please show me on the code (in red maybe?) what I have to change in your code and also maybe an exemple?

It will be more clear to me.

THANKS!
 
strTwo = "docs/" & strFile
change docs/ to the relative path to where ever your files are.

When you wish to use this you just use the link as above.

Cheech

[Peace][Pipe]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top