1 Reply Latest reply on Oct 9, 2008 4:57 AM by Newsgroup_User

    upload image

    masoud_amen Level 1
      hi.I wrote this code for uploading the images to my folder:

      <cfset processDir = "E:\www\NeedBattery\images\test\">
      <cfset itemsDir = "E:\www\NeedBattery\images\icons\">
      <cfset saveFile = form.catStripped & ".gif">
      <cfset saveDbFile = form.catStripped & ".gif">
      <cfset imageCFC = CreateObject("component", "includes.imagecfc.image")>

      <!--- save image for processing --->
      <cffile action="upload" filefield="catImage" destination="#processDir#" nameconflict="overwrite">

      <cfif cffile.fileWasSaved>
      <!--- check if file uploaded is an image --->
      <cfif (cffile.serverFileExt IS "jpg") OR (cffile.serverFileExt IS "gif") OR (cffile.serverFileExt IS "png")>
      <!--- get image info --->
      <cfset imageInfo = imageCFC.getImageInfo("", #cffile.serverDirectory# & "\" & #cffile.serverFile#)>
      <!--- resize image if necessary --->
      <cfif (imageInfo.height GT 150) OR (imageInfo.width GT 150)>
      <cfset resizeImage = imageCFC.resize("", #cffile.serverDirectory# & "\" & #cffile.serverFile#, #cffile.serverDirectory# & "\" & #cffile.serverFile#, 42, 42, "true", "true")>
      <cfset imageInfo = imageCFC.getImageInfo("", #cffile.serverDirectory# & "\" & #cffile.serverFile#)>
      </cfif>

      <cfset imageInfo = imageCFC.getImageInfo("", cffile.serverDirectory & "\" & cffile.serverFile, itemsDir & saveFile)>

      <!--- delete image from process dir for cleanup --->
      <cffile action="delete" file="#cffile.serverDirectory#\#cffile.serverFile#">

      <!--- update db with new image filename --->
      <CFQUERY name="updateImage" datasource="#session.eManager.datasource#">
      UPDATE tbl_cat_level1
      SET cat_level1_image = '#saveDbFile#'

      WHERE cat_level1_id = #form.catID#
      </CFQUERY>

      <cfelse>
      <!--- if not an image, delete --->
      <cffile action="delete" file="#cffile.serverDirectory#\#cffile.serverFile#">
      </cfif>
      </cfif>


      it didnt give any error but its not working.I couldnt find what is my mistake.plz someone help.
      thanks
        • 1. Re: upload image
          Level 7
          i am sure you did not really mean to call the getImageInfo method in
          this line:

          <cfset imageInfo = imageCFC.getImageInfo("", cffile.serverDirectory & "\" &
          cffile.serverFile, itemsDir & saveFile)>

          you probably meant to call writeImage or similar method instead, because
          you are not actually saving your resized image anywhere, just deleting
          the uploaded image... hence no image...

          hth


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