Verify remote images exist - prevent missing images with CFHTTP
I am creating a photo gallery where the images actually reside on a third-party service. To prevent 'blank' or missing images from showing up in my html gallery markup, I needed a way to verify the remote image actually exists before including it into the dynamic
This seems to work quite nicely:
<cfoutput query="myImageQuery">
<cfset imgURL = "http://remotesite.com/images/#imageFilename#">
<!--- check for the image via cfhttp:
Note:'head' method gets only headers, which is all we need (thanks @ScottP) --->
<cfhttp url="#imgURL#" method="head">
<!--- isolate the 'mimeType' value from the cfhttp results --->
<cfset myStatus = cfhttp.mimeType>
<!--- if the mimeType is jpg (jpeg), include the image in our output --->
<cfif myStatus eq "image/jpeg">
<img src="#imgURL#" alt="#imageTitle#">
</cfif>
</cfoutput>

