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

Stream File to Browser 1

Status
Not open for further replies.

hedidit

Technical User
Jul 21, 2005
142
GB
Hi,

I have a downloads page that lists files located ina folder not in the webroot. I've found some code that streams the file to the browser however I want the user to be prompted to download the file, at the moment it is shown on-screen... zip files show up as loads of random text... not nice!

I've seen lots of posts on these forums but nothing that seems to help... can someone point me in the write direction?

My code is currently:

Code:
strFilePath = server.mappath("../../database/" & Session("ORG") & "/") & "/" & Request("FN")
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = 1
objStream.LoadFromFile strFilePath
fn = Request("FN")
Response.ContentType = "application/octet-stream"
Response.AddHeader "Content-Disposition","attachment;filename=" & fn
Response.BinaryWrite objStream.Read
objStream.Close
Set objStream = Nothing

Cheers
 
are the mime types registered on IIS correctly?

Take a look here

it will help you with your zip issues.

[sub]____________ signature below ______________
The worst mistake you'll ever make is to do something simply the way you know how while ignoring the way it should be done[/sub]
 
Hi Oonpt,

Thanks as always, unfortunately the site is on a hosted server however that article did help! Now the save file prompt appears but leaves the .zip off the name of the file... any thoughts?

 
Ok that's wired... the download prompt works fine in IE7 but Firefox downloads the file without the file extension... most of my users will be using IE so I'm happy but how odd!
 
That is odd. One thing I would warn you about is to not put the Request("FN") variable directly in your filepath without doing some basic checks on it. As it is, it wouldn't be too hard for someone to inject a bad value into it and start downloading files you hadn't intended them to download. With enough playing around they could probably find other files to download, or put enough ..'s to get themselves back to the root of the drive and then find system settings files.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top