I am currently trying to upload a file using a function from a cfc file. I can get the code to work when I just call the <cffile action="upload">
on the same page. However, I wanted to learn how to call it from a function in a cfc file. I believe there is a problem with the arguments I'm passing to the attributes of the <cffile>
tag, but I'm not sure.
Here is my HTML form:
<form action="confirm.cfm" method="POST" enctype="multipart/form-data">
First Name: <input type="text" name="FNAME" size="25" /> <br />
Last Name: <input type="text" name="LNAME" size="30" /> <br />
Upload Attachment File Here: <input type="file" name="fileUpload"
id="fileUpload" size="30"
onchange="PassFileName()" /> <br />
<input type="hidden" name="fileName" id="fileName" /> <br />
<input type="submit" value="submit" />
<input type="reset" name="Reset Form" />
<div id="filenamesection">
</div>
</form>
Here is the code that the form is submitting to the confirm.cfm page
<cfif isDefined("Form.fileUpload")>
<cfinvoke component="FileUploadExample"
method="UploadFile"
fileToUpload="#Form.fileUpload#"
sizeMax="50"
returnvariable="FileNameReturn">
<cfelse>
<cflocation url="index.cfm">
</cfif>
<h1> Thank for filling out this form </h1>
<cfoutput>
<table>
<h3> Please review and confirm the information below </h3>
<tr>
<td> is this the first name you entered </td>
<td> #Form.FNAME# </td>
</tr>
<tr>
<td> is this the last name you entered </td>
<td> #Form.LNAME# </td>
</tr>
<tr>
<td> is this the name of the file you uploaded? </td>
<td> #Form.fileName# </td>
</tr>
</table>
</cfoutput>
The File <cfoutput> #Form.fileName# </cfoutput> has been uploaded
Here is the code from my FileUploadExample.cfc file
<cfcomponent>
<cffunction name="uploadFile" access="public" output="no" returntype="string">
<cfargument name="fileToUpload" type="string" required="no">
<cfset var cffile="">
<cffile action="upload"
destination="C:\filepath\example\whatevaFolder\"
filefield="#ARGUMENTS.fileToUpload#"
nameconflict="overwrite">
<cfreturn cffile.clientFile>
</cffunction>
</cfcomponent>
The error I keep receiving when I upload a file is:
neotmp84939430443.tmp did not contain a file.