Skip to main content
lovewebdev
Inspiring
March 1, 2009
Question

Check if image Exists, Bug in function.

  • March 1, 2009
  • 1 reply
  • 453 views
I found a function that checks to see if an image exists. I pasted it below, but there seems to be this weird bug. If a subdomain is in the url of the image but the subdomain is wrong, you'll get an exception saying: Element Content-Type is undefined in a CFML structure referenced as part of an expression.

For example, if the correct url is:
http://images.whatever.com/photos/man.jpg

and you change the subdomain like so:
http://imag.whatever.com/photos/man.jpg

The weird thing is that it works even if you mess up the domain name, directories or image name, but not the subdomain.

original code here:
http://www.succor.co.uk/index.cfm/2007/3/18/How-to-check-if-an-image-exists-with-HTTP


    This topic has been closed for replies.

    1 reply

    lovewebdev
    Inspiring
    March 1, 2009
    I see what was happening, if the subdomain was wrong, no responseheaders were being returned so I adjusted the code to check if response headers are being returned first.

    <cfif NOT StructIsEmpty(cfhttp.responseHeader) AND listFind("image/jpeg,image/gif,image/png",cfhttp.responseHeader["Content-Type"])>