Form File Upload Function
This seems like a dumb question, but I am on a tight deadline and don't have a ton of time to muck around trying to figure it out.
Building a form which takes up to 4 images to upload. The form gets passed to a function that is supposed to handle the image uploading.Problem is, when a form filed gets passed to a function, it doesn't seem to be valid any longer. Like all the examles you see online just have the cffile line and the form all on the same page, no functions involved. So now when I try to have a function handle the uploading, I get errors like
The form field arguments.image did not contain a file.
C:\ColdFusion9\runtime\servers\coldfusion\SERVER-INF\temp\wwwroot-tmp\neotmp3794510969991376318.tmp
The calls to the image uploader function look like
<!--- Handle File Uploads ---->
<cfif structKeyExists(form, "image1")>
<cfset returnStruct.image1 = uploadImage(form.image1)>
</cfif>
<cfif structKeyExists(form, "image2")>
<cfset returnStruct.image2 = uploadImage(form.image2)>
</cfif>
<cfif structKeyExists(form, "image3")>
<cfset returnStruct.image3 = uploadImage(form.image3)>
</cfif>
<cfif structKeyExists(form, "image4")>
<cfset returnStruct.image4 = uploadImage(form.image4)>
</cfif>
The upload image function looks like
<cffunction name="uploadImage" access="private" returntype="struct" description="Upload a given image">
<cfargument name="image" type="any" required="yes">
<cfset var returnstruct = structnew()>
<cfset returnStruct.message = "function ran successfully">
<cfset returnstruct.success = true>
<cfset returnStruct.file = arguments.image>
<cftry>
<cfset destination = expandPath("./files")>
<cfif not directoryExists(destination)>
<cfdirectory action="create" directory="#destination#">
</cfif>
<cffile action="upload" filefield="arguments.image" destination="#destination#" nameConflict="makeUnique" result="upload">
<cfset returnStruct.uploadResult = upload>
<cfset returnStruct.newName = createUUID()&serverFileExt>
<cffile action="rename" destination="#destination##returnStruct.newName#" source="#destination##serverFileName##serverFileExt#" >
<cfcatch type="any">
<cfset returnStruct.message = cfcatch.message>
<cfset returnstruct.success = false>
</cfcatch>
</cftry>
<cfreturn returnStruct>
</cffunction>
Any thoughts on what I'm doing wrong?
