scimitar
04-22-2007, 07:33 PM
Hi guys
Newbie here, so be gentle! I'm looking at having some files uploaded to my site which, when someone clicks on them, they are prompted to download rather than have them open in the browser (due to size and reason for having them there).
I've downloaded the following script from a website but, not knowing anything really about VB or ASP scripting, amd really stuck on how to get this to work.
Basically, I have a hyperlink which, when clicked, should prompt the user to download a file. The file, for arguments sake, will be Doc1.pdf. The filedownloader.asp file will be held in the cgi-bin folder (I'm assuming that's the right place for an ASP file?).
The site I got this from instructed me to use the following link:
http://mydomain/filedownloader.asp?filename=Doc1.pdf
Altering this to:
http://mydomain/cgi-bin/filedownloader.asp?filename=Doc1.pdf
to put the ASP into the CGI-BIN folder, the hyperlink works, the dialogue box comes up but instead of downloading the Doc1.pdf file it tries to download the fileuploader.asp file instead!
Can anyone please show me what bits of this coding I need to replace with what file references in order to get this to work? Trying to read through some of the other forums it is very difficult to follow and it's driving me mad!! Therefore some plain English would be great!
Thanks in advance!
Lee
<%
'=======================
'Define the names of your functions
'=======================
Dim Stream
Dim Contents
Dim FileName
Dim FileExt
Const adTypeBinary = 1
'=======================
'Get the actual file name from the URL that is passed to the browser
'=======================
FileName = request.querystring("filename") 'Get the name from the URL
'=======================
'GIVE AN ERROR MESSAGE IF THE URL IS EMPTY
'=======================
if FileName = "" Then
response.write "Filename Not specified."
response.end
end if
'=======================
'prevent access to certain files
'=======================
FileExt = Mid(FileName, InStrRev(FileName, ".") + 1)
select case UCase(FileExt)
Case "ASP", "ASA", "ASPX", "ASAX", "MDB"
response.write "You cannot access these file types."
response.end
end select
'=======================
'Start the download process if all is good
'=======================
response.clear
response.contentType = "application/octet-stream"
response.addheader "content-disposition", "attachment; filename=" & FileName
set stream = server.CreateObject("ADODB.Stream")
stream.type = adTypeBinary
stream.open
stream.LoadFromFile Server.MapPath("/files") & FileName
while not stream.EOS
response.BinaryWrite Stream.Read(1024 * 64)
wend
stream.Close
Set stream = Nothing
response.Flush
response.End
%>
Newbie here, so be gentle! I'm looking at having some files uploaded to my site which, when someone clicks on them, they are prompted to download rather than have them open in the browser (due to size and reason for having them there).
I've downloaded the following script from a website but, not knowing anything really about VB or ASP scripting, amd really stuck on how to get this to work.
Basically, I have a hyperlink which, when clicked, should prompt the user to download a file. The file, for arguments sake, will be Doc1.pdf. The filedownloader.asp file will be held in the cgi-bin folder (I'm assuming that's the right place for an ASP file?).
The site I got this from instructed me to use the following link:
http://mydomain/filedownloader.asp?filename=Doc1.pdf
Altering this to:
http://mydomain/cgi-bin/filedownloader.asp?filename=Doc1.pdf
to put the ASP into the CGI-BIN folder, the hyperlink works, the dialogue box comes up but instead of downloading the Doc1.pdf file it tries to download the fileuploader.asp file instead!
Can anyone please show me what bits of this coding I need to replace with what file references in order to get this to work? Trying to read through some of the other forums it is very difficult to follow and it's driving me mad!! Therefore some plain English would be great!
Thanks in advance!
Lee
<%
'=======================
'Define the names of your functions
'=======================
Dim Stream
Dim Contents
Dim FileName
Dim FileExt
Const adTypeBinary = 1
'=======================
'Get the actual file name from the URL that is passed to the browser
'=======================
FileName = request.querystring("filename") 'Get the name from the URL
'=======================
'GIVE AN ERROR MESSAGE IF THE URL IS EMPTY
'=======================
if FileName = "" Then
response.write "Filename Not specified."
response.end
end if
'=======================
'prevent access to certain files
'=======================
FileExt = Mid(FileName, InStrRev(FileName, ".") + 1)
select case UCase(FileExt)
Case "ASP", "ASA", "ASPX", "ASAX", "MDB"
response.write "You cannot access these file types."
response.end
end select
'=======================
'Start the download process if all is good
'=======================
response.clear
response.contentType = "application/octet-stream"
response.addheader "content-disposition", "attachment; filename=" & FileName
set stream = server.CreateObject("ADODB.Stream")
stream.type = adTypeBinary
stream.open
stream.LoadFromFile Server.MapPath("/files") & FileName
while not stream.EOS
response.BinaryWrite Stream.Read(1024 * 64)
wend
stream.Close
Set stream = Nothing
response.Flush
response.End
%>