What am I doing wrong?
fileUpload.cfm
<cfcomponent name="fileAttachment" hint="This is the File Attachment Object">
<cffunction name="uploadFile" access="public" output="no" returntype="string">
<cfargument name="fileToUpload" type="string" required="no">
<cfargument name="pDsn" required="no" type="string">
<cfset var cffile = "">
<cffile action="upload" destination="D:\apache\htdocs\abc\uploads" filefield="#ARGUMENTS.fileToUpload#" nameconflict="makeunique">
<cfreturn cffile.clientFile />
</cffunction>
</cfcomponent>
test_fileUpload.cfm
<form action="fileUpload.cfm" enctype="multipart/form-data" method="post">
<input type="file" name="fileToUpload"><br/>
<input type="submit">
</form>
This line:
The filefield attribute wants the name of the form field that will hold the uploaded file. You’re on the right track, but unfortunately, that’s not what the value of
#ARGUMENTS.fileToUpload#is, presently–based on your construction, it holds a reference to the actual file itself.Add a new hidden field to your form:
Then, pass
FORM.nameOfFieldto your uploadFile() method as the first parameter. CFFILE will take care of the rest.