We help IT Professionals succeed at work.
Get Started

Cold Fusion Image Resize not working

swaggrK
swaggrK asked
on
579 Views
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"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>

<body>
<cfif structKeyExists( FORM, 'imageName' )  >
<cftry>

    <!--- Kevin's standard upload code: begin --->
	<cfscript>  foo = ExpandPath("*.*");  bar = GetDirectoryFromPath(foo);  
dirCount = listLen(bar,"\");  myDir = listGetAt(bar, dirCount - 1, "\")
;</cfscript>
<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>
				</cfif>           
            <!--- End Loop after 5 minutes --->
            <cfset currentTime = getTickCount()>
            <cfset timeLapsed = (currentTime - beginTime)/1000>
            <cfif timeLapsed GTE 5>
                  <cfset fileRead = true>
            </cfif>
      </cfloop>
	<cfif cffile.fileWasSaved>
		Upload successful!
		<cfset pic = imageread(#thePath#)>
	
		 <cfimage action="resize" 
		 width="300" 
		 height="" 
		 source="#pic#" 
		 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#">)
		</cfquery>

	<cfelse>
	Error:
	<cfoutput>#cfcatch.Message#</cfoutput>
	</cfif>
<cfcatch>

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

</cftry>




<cfelse>

	
<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" /> 
</form>

</cfif>
</body>
</html>
                                            

Open in new window

Comment
Watch Question
CERTIFIED EXPERT
Most Valuable Expert 2015
Commented:
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