prompt "Save as" dialog for image

D

dave

Hi there
I'm trying to force save as dialogue using this code in download.asp..but
when it runs it prompts for download.asp to save or open.

code snippet (from aspfaq.com)

Response.ContentType = "application/x-unknown" ' arbitrary
fn = "wallpaper_1_1.jpg"
Response.write "<br>" & Server.MapPath("wallpaper") & "<br>"
FPath = Server.MapPath("wallpaper") & fn
Response.AddHeader "Content-Disposition","attachment; filename=" & fn

Set adoStream = CreateObject("ADODB.Stream")
adoStream.Open()
adoStream.Type = 1
adoStream.LoadFromFile(FPath)
Response.BinaryWrite adoStream.Read()
adoStream.Close
Set adoStream = Nothing


I want this page to prompt save image option, not page itself.

Any help would be appreciated!!!
 
R

Ray Costanzo [MVP]

Do you have an On Error Resume Next? Well, regardless, a couple of changes
will be necessary.

When you Response.write FPath, did you notice that there was no \ between
the directory name and the filename? You'll need that. Also, make sure you
do not leave the Response.Write code in there when you get this working.
Try this code:

Response.ContentType = "application/x-unknown" ' arbitrary
fn = "wallpaper_1_1.jpg"
'Response.write "<br>" & Server.MapPath("wallpaper") & "<br>"
FPath = Server.MapPath("wallpaper") & "\" & fn
Response.AddHeader "Content-Disposition","attachment; filename=" & fn

Set adoStream = CreateObject("ADODB.Stream")
adoStream.Open()
adoStream.Type = 1
adoStream.LoadFromFile(FPath)
Response.BinaryWrite adoStream.Read()
adoStream.Close
Set adoStream = Nothing

Ray at home
 
D

dave

yeh man, it worked
thanx for help
dev

Ray Costanzo said:
Do you have an On Error Resume Next? Well, regardless, a couple of changes
will be necessary.

When you Response.write FPath, did you notice that there was no \ between
the directory name and the filename? You'll need that. Also, make sure you
do not leave the Response.Write code in there when you get this working.
Try this code:

Response.ContentType = "application/x-unknown" ' arbitrary
fn = "wallpaper_1_1.jpg"
'Response.write "<br>" & Server.MapPath("wallpaper") & "<br>"
FPath = Server.MapPath("wallpaper") & "\" & fn
Response.AddHeader "Content-Disposition","attachment; filename=" & fn

Set adoStream = CreateObject("ADODB.Stream")
adoStream.Open()
adoStream.Type = 1
adoStream.LoadFromFile(FPath)
Response.BinaryWrite adoStream.Read()
adoStream.Close
Set adoStream = Nothing

Ray at home
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top