Skip to main content
September 4, 2008
Question

Don't want to display images

  • September 4, 2008
  • 4 replies
  • 461 views
Hello again. I have setup ImageCFC on my site and it seems to be working fairly well. However, every once in awhile it won't write an image to the hard drive when it says it has. I have an insert statement that adds an indicator to my db once the image file has been saved to the disk with the cfc.

Some of the images don't get saved even though the insert runs AFTER the writing of the file. Is there a way to read the image on the hard disk before displaying it to the screen to make sure its there? I hate displaying the ugly red x when an image isn't there. I tried cffile "read" and that returned an error when the file wasn't there. http://livedocs.adobe.com/coldfusion/7/htmldocs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=ColdFusion_Documentation&file=00000245.htm

Is there a way to look at the file and if its there, display it, if not, don't. Otherwise how do I solve this prior to the db insert statement so the table isn't lying to me.
    This topic has been closed for replies.

    4 replies

    September 5, 2008
    It just doesn't do what its supposed to. The code runs and there aren't any errors. However when I check to see if there was a new pic created it isn't there. Weird.
    Inspiring
    September 5, 2008
    what's the error? you may have to set throwonerror to YES...


    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com/
    September 5, 2008
    Great. Now the Image CFC problem... This used to work fine and now it does not. Anyone have a guess?



    <!--- Get thumb and create cropped from it --->
    <cfquery name="get_thumb_to_crop1" datasource="myds">
    SELECT pic_path_small FROM pics WHERE id = '123'
    </cfquery>
    <!--- cfc --->
    <cfscript>
    imagecfc = createObject("component","image");
    imagecfc.setOption("throwOnError","No");
    create_thumb_blur = imagecfc.filterFastBlur("","#ExpandPath(".")#/thumbnails/#get_thumb_to_crop1.pic_path_small#","#ExpandPath(".")#/thumbnails/cropped_thumbnails/#image_path1#",2,1);
    create_thumb_crop = imagecfc.resize("","#ExpandPath(".")#/thumbnails/cropped_thumbnails/#image_path1#","#ExpandPath(".")#/thumbnails/cropped_thumbnails/#image_path1#",70,70, true, true);
    </cfscript>
    Inspiring
    September 5, 2008
    you can use fileexists() function to check if a file exists on the disk.
    more details in the docs.

    alternatively, you can use the not-so-well know onError event in img
    tags to change the image source to some default "image not available"
    image. this requires js support in browser to be enabled:

    <img src="someimage.jpg" onError="this.src='notfound.jpg'">


    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com/