我目前正在尝试使用 cfc 文件中的函数上传文件。<cffile action="upload">
当我在同一页面上调用时,我可以让代码工作。但是,我想学习如何从 cfc 文件中的函数调用它。我相信我传递给<cffile>
标签属性的参数有问题,但我不确定。
这是我的 HTML 表单:
<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>
这是表单提交到 confirm.cfm 页面的代码
<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
这是我的 FileUploadExample.cfc 文件中的代码
<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>
我上传文件时不断收到的错误是:
neotmp84939430443.tmp 不包含文件。