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

cfcontent image/jpeg not working in img tags

Status
Not open for further replies.

jstreich

Programmer
Apr 20, 2002
1,067
US
I have the following code in image.cfm ... If I go to image.cfm I'm served the jpeg file perfectly. If I use it in an image tag it doesn't show up.

Code:
<cfsilent>
[red]...[/red]
<cffile action="readbinary" file="C:\CFusionMX7\[URL unfurl="true"]wwwroot\superman.jpg"[/URL] variable="binData" />
</cfsilent>

<cfcontent type="image/jpeg" variable="#binData#" reset="true">

I have in the page where it's supposed to be
Code:
<img src="image.cfm" alt="Grrr..."/>

Ideas?

[plug=shameless]
[/plug]
 
I do this a lot, but I've never used cffile with it.
Code:
<img src="image.cfm?I=#UrlEncodedFormat('superman.jpg')#" alt="Grrr..."/>
Code:
<cfset images_path = "images\superheroes\">	
<cfcontent type="image/jpg" file="#images_path##Url.I#">


Hope This Helps!

ECAR
ECAR Technologies

"My work is a game, a very serious game." - M.C. Escher
 
Thank you for your ideas.

I botched the img tag, and because it was just an img tag I just retyped it above instead of copy/paste from the code. The method I posted works. File="" should work, but didn't seem to be for me.

That said, I need to be able to determine in the image.cfm what page the picture is on, even if it's used in the css (included css file) of the page. So is there a way to know the browser's URL in such an instance? #cgi.http_referer# doesn't seem to be the page the image is on, like I thought it would for a simple img tag.

[plug=shameless]
[/plug]
 
CGI.REFERER should work.

Norton Security / Internet Security blocks referer info by default - so you may have some users not seeing photos.



Kevin

Phase 1: Read the CFML Reference
Phase 2: ???
Phase 3: Profit!
 
The referer seems to be the referer for the page with the img on it... read: if I go the page with img tag directly, the referer is blank. The script_name seems to give me the image.cfm file, and not the page the img tag is on.

hm.

[plug=shameless]
[/plug]
 
Correction. It's not blank, but isn't the page the image is on either. It is, however, something from the same domain... So referer works for protecting against hotlinking. But not on changing images on a per page basis.

[plug=shameless]
[/plug]
 
But not on changing images on a per page basis
You never really came out and said that was what you are trying to do. All you have to do is pass the name of the image as a url paramater to image.cfm, then have image.cfm display the appropriate image. Then you can have it display as many different images as you want, on as many different pages as you want...just change the name in the link.



Hope This Helps!

ECAR
ECAR Technologies

"My work is a game, a very serious game." - M.C. Escher
 
Agreed. I figured the code was just a demo of the problem and he was doing as you said - but good point.

I use this on a few sites that are prone to having images posted in forums - this way I can force a small thumbnails to save bandwidth, while still allowing the image to be posted - or even track a users hotlinked bandwidth and cut them off if exceeded.

Kevin

Phase 1: Read the CFML Reference
Phase 2: ???
Phase 3: Profit!
 
Not so much demo code, but my proof of concept...

The issue was that I was writting a very small cfm file for another web developer, who just writes plain HTML and CSS. He was trying to use different images as the background of different pages all attached at the bottom of the page (as backgrounds to divs) with no-repeat, and he didn't want to write a whole bunch of css files, with basically the same code. I offered several (better solutions than the cfm image)to the problem, but they were all shot down, because he's convinced himself the problem has no solution.

What I ended up doing, in the end, was to make a dynamically CSS file in coldfusion that takes the image, the class and an optional background color and generate a CSS file.

The image code above I kept and modified to make a random image swapper (that is different image on each load), and another as a means of preventing hot-linking (which I don't personally have a need for, but I'm sure will be used by someone or other in this giant orginiztion).

[plug=shameless]
[/plug]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top