我目前正在嘗試使用cfc文件中的函數上傳文件。當我在同一頁面上調用<cffile action="upload">
時,我可以獲取代碼。不過,我想學習如何從cfc文件中的函數中調用它。我相信我傳遞給<cffile>
標記的屬性存在一個問題,但我不確定。從cfc文件不工作的Coldfusion FileUpload功能
這裏是我的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 did not contain a file.
要分離問題,請在.cfm文件中運行您的cffile代碼。 – 2013-05-08 14:45:01