troubleshooting Question

coldfusion-Image tag - check external image file

Avatar of Panos
PanosFlag for Germany asked on
ColdFusion Language
6 Comments1 Solution500 ViewsLast Modified:
Hello experts.
I want to show images using "external" images (images not on my server).
f.e the experts-exchange logo.
<img src=""/>

This is OK. But the problem appears if f.e the image don't exist.
I thought that it would be nice to use this tutorial: with a little change.
My image tag:
<img src="showimage.cfm?imageurl=">

My showimage.cfm page:
(i added the urlexists function from this tutorial:
  <cffunction name="URLExists" output="no" returntype="boolean">
    <!--- Accepts a URL --->
    <cfargument name="u" type="string" required="yes">
    <!--- Initialize result --->
    <cfset var result=true>
    <!--- Attempt to retrieve the URL --->
    <cfhttp method="head" url="#ARGUMENTS.u#"
            resolveurl="no" throwonerror="no" />
    <!--- Check if no status code or status code 404 --->
    <cfif NOT IsDefined("cfhttp.responseheader.status_code")
            OR cfhttp.responseheader.status_code EQ "404">
        <!--- Does not exist, return FALSE --->
        <cfset result=false>
   <cfreturn result>
      <cfparam name="URL.imageurl" type="string" default="" />
    <cfset urlexist = urlExists(URL.imageurl) />
    <cfif urlexist EQ true>
      <cfset strURL = URL.imageurl />
      <cfset strURL = "image_not_found.gif" />
    <!--- Forward image request to actual image file. --->
      <cflocation url="#strURL#" addtoken="false" />

That is checking if the requested page is throwing any error.
1.Well i don't know if this is the best way to do this.
2.It doesn't ensure the image output. The requested page could be a page like"This image don't exists" and i will not get any error.

Any help?
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 6 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros