Skip to main content
lovewebdev
Inspiring
March 2, 2011
Question

Send image to browser with <cfcontent> not download prompt

  • March 2, 2011
  • 4 replies
  • 3437 views

I'm sending an image to be downloaded using cfcontent

<cfheader name="Content-disposition" value="attachment;filename=#getit.file#">

<cfcontent type="image/jpg" file="#physicalpath#\#getit.file#">

Can I have the image sent to the browser instead of a download prompt?

This topic has been closed for replies.

4 replies

lovewebdev
Inspiring
March 2, 2011

It's because the images are being stored in a folder above the public root folder...

Could I just put that as the value of an <img> tag?

Community Expert
March 3, 2011

If the image isn't accessible directly via HTTP, you can use CF to serve it. Your CF page would have the CFCONTENT tag as you showed in your original post, then you'd use IMG tags in other pages pointing to that CF page:

<img src="myimage.cfm?id=whatever"/>

You wouldn't need the CFHEADER to specify it as an attachment, though - that's only for when you want to prompt the user to download a file without having it handled natively by the browser.

Dave Watts, CTO, Fig Leaf Software

http://www.figleaf.com/

http://training.figleaf.com/

Dave Watts, Eidolon LLC
lovewebdev
Inspiring
March 3, 2011

Awesome, that actually worked really well. i didn't know you could do that.

Is there a way to do something similar to documents: so say a pdf or word loads in the browser as opposed to download as well

Owainnorth
Inspiring
March 2, 2011

I really do hope we're missing something here.

Inspiring
March 2, 2011

You are •specifically telling it• to be treated as an attachment. If you don't want to do that, then stop telling it to!

--

Adam

Inspiring
March 2, 2011

<img>