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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Download via ASP. 1

Status
Not open for further replies.

JohnCMolyneux

Programmer
Jun 22, 2004
24
0
0
GB
Hi.

I've built a download for a website and I want to add logging of downloads. I want to do this via ASP so that a normal download link (with a URL ending in a filename) can be replaced with something like...


...where id=15 refers to a filename stored in a database.

I can do everything I need, except the actual download.

For example, if I did the following...


...how do I make ASP return the file "instructions.txt"?

Thanks in advance,

John.

mf_of_john.gif
 
thinking at the keyboard (always a dangerous thing)

Code:
dim url
if request.querystring("file") <> "" then
url = "/downloadpath/" & request.querystring("file")
response.redirect(url)

should work I guess.


Chris.

Indifference will be the downfall of mankind, but who cares?
A website that proves the cobblers kids adage.
Nightclub counting systems

So long, and thanks for all the fish.
 
Alternatively, you could actually store the file itself in a database, so that when you select fomr the database by the ID, you actually return the file, instead of just the location on the webserver. Research the BLOB field type and decide if it's something you might want to do.
 
Thanks disorder, but I've already discounted using the database, as I usually do with anything that's file based.

John.

mf_of_john.gif
 
Actually, the suggestion that Chris gave is not actually what I'm looking for - I'm trying to not give the filename via the URL.

I'll have to look into attaching files to HTML and pass the filename back via that method instead.

John.

mf_of_john.gif
 
If you just want to write a link to the page then this will do

Code:
if request.querystring("file") <> "" then
with response
.write "<a href='/filepath/"
.write request.querystring("file")
.write "'>Download "
.write request.querystring("file")
.write "</a>
end with
end if



Chris.

Indifference will be the downfall of mankind, but who cares?
A website that proves the cobblers kids adage.
Nightclub counting systems

So long, and thanks for all the fish.
 
Erm, no, thanks Chris. I'm going to look into attaching the file to HTML so as not to give a direct URL to anything.

John.

mf_of_john.gif
 
You just have to use the Scripting.FileSystemObject to read the content of the binary file, then use Response.BinaryWrite to send it to the browser for downloading.
 
see thread entitled "binary stream issues" there's alot of discussion of how to get this to work for you

in the download page you would just do a ref# to file translation, through your db, then you could also up your request count, or log ip or whatever it is you're wanting to do at this point, then FSO to the file, and then stream it.



[thumbsup2]DreX
aKa - Robert
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top