We help IT Professionals succeed at work.
Get Started

Cold Fusion Image Resize not working

swaggrK asked
Last Modified: 2012-08-17
I am using the following code to upload and then resize an image. The code uploads but does not resize the image.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>

<cfif structKeyExists( FORM, 'imageName' )  >

    <!--- Kevin's standard upload code: begin --->
	<cfscript>  foo = ExpandPath("*.*");  bar = GetDirectoryFromPath(foo);  
dirCount = listLen(bar,"\");  myDir = listGetAt(bar, dirCount - 1, "\")
<cfset oneupDirectory = ListDeleteAt("#bar#",ListLen("#bar#","\"),"\")>

<cfset hardPath = "#oneupDirectory#\p">

<cfset thePath="#hardPath#\#form.imageName#.jpg"><!--- set the absolute path to the image --->
<cffile action="upload" filefield="form.myImage"	destination="#thePath#"
	nameconflict="overwrite"         accept="image/gif, image/jpg, image/jpeg, image/pjpeg"> 
	   <cfset fileRead = false> <!--- give some time to upload, prevents trying to resize an image not completely uploaded --->
      <cfset beginTime = getTickCount()>
      <cfloop condition="fileRead EQ false">
		<CFIF FileExists(#thePath#)>
		 <cfset fileRead = true>
            <!--- End Loop after 5 minutes --->
            <cfset currentTime = getTickCount()>
            <cfset timeLapsed = (currentTime - beginTime)/1000>
            <cfif timeLapsed GTE 5>
                  <cfset fileRead = true>
	<cfif cffile.fileWasSaved>
		Upload successful!
		<cfset pic = imageread(#thePath#)>
		 <cfimage action="resize" 
		 destination="#thePAth#" overwrite="yes"> 
		 <!--- resize the image --->
		<cfquery name="imgInsert" datasource="yourDSN">
		<!--- insert into db --->
		insert into mytable (imageid, Imagename) values (<cfqueryparam cfsqltype="cf_sql_integer" value="#createuuid#">,<cfqueryparam cfsqltype="cf_sql_varchar" value="#form.imageName#">)


        <cfif FindNoCase("not accepted", cfcatch.Message)>
           <cfset error ="Only the following file types are allowed: .jpg, .gif, .bmp, .png.">
<cfoutput>               #error#</cfoutput>



<form id="uploadForm" action="upload.cfm" method="post" enctype="multipart/form-data"> 
    Upload Image: <input type="file" name="myImage" /> 
	Image Name: <input type="text" value="" name="imageName">
    <input type="submit" value="Upload" /> 


Open in new window

Watch Question
Most Valuable Expert 2015
This problem has been solved!
Unlock 1 Answer and 12 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE