1

A lot of images from my company database have non-conventional names such as "st. john's.jpg". In cf8, I used URLEncodedFormat(myimage) inside IsImageFile to check such images(see my code below). It worked perfectly until I moved to cf9. It seems like cf9 doesn't recognize URLEncodedFormat files inside IsImageFile. Please advise how I can make cf9 check images with both conventional and non-conventional names.

<cfif IsImageFile("http://www.mywebsite.com/images/#URLEncodedFormat(myimage)#")>
  <cfset imageURL = "/images/#URLEncodedFormat(myimage)#">
<cfelse> 
  <cfset imageURL = "/images/noimage.jpg">
</cfif>
Peter Boughton
  • 110,170
  • 32
  • 120
  • 176
Dmitry
  • 4,143
  • 10
  • 46
  • 57
  • Assuming you're checking the exact same myimage value on both versions, it sounds like a bug - have you raised it on the [Adobe bug tracker](https://bugbase.adobe.com/)? – Peter Boughton Sep 06 '12 at 17:13
  • 2
    What's the exact error. Maybe it's not the filename. http://stackoverflow.com/questions/11434403/coldfusion-isimagefile-fails-for-jpg-file-wtf – ale Sep 06 '12 at 20:03
  • I raised question in Adobe bug tracker. Hopefully someone will help. I wish I could output the error. It seems cfif conditional only return false and sets imageURL to "/images/noimage.jpg" – Dmitry Sep 07 '12 at 15:26
  • 1
    I know this doesn't actually fix the exact issue you're having, but you could switch to using `cfhttp` to check for the image file. You would make the `cfhttp` request, and then check the status and bytes of the image to make sure it's an image file. You can use the code from http://stackoverflow.com/questions/1536815/convert-an-image-from-cfhttp-filecontent-to-binary-data-with-coldfusion/1537433#1537433 as a start for your script. – Dan Short Sep 07 '12 at 15:45

1 Answers1

0

The way you have written the if statement leads me to believe that you are including the file extension within the "myimage" variable. If this is the case then it would the "." (period) getting converted to "%2E".

If this is correct, I would suggest the following to resolve:

<cfscript>
  basePath  = "http://www.mywebsite.com";
  image     = "freds's image.jpg";
  name      = URLEncodedFormat(listFirst(image, "."));
  extension = listLast(image, ".");
  imageUrl  = "/images/#name#.#extension#";

  if (! isImageFile(basePath & imageUrl)) {
    imageUrl = "/images/noimage.jpg";
  }

</cfscript>
AlexP
  • 9,906
  • 1
  • 24
  • 43