我正在尝试对 cffile 上传进行例外处理,以确保用户只上传与 xls 相关的文档或根本不上传。我的文件上传有问题。即使用户可能没有将任何内容附加到输入,表单仍将通过并假定表单字段 b1b3formAttach 已定义。这是代码:
<cfif structKeyExists(form, "Submit")>
<cfif isDefined("Form.b1b3formAttach") >
<cffile action = "upload"
fileField = "b1b3formAttach"
destination = "#GetTempDirectory()#"
nameConflict = "overwrite">
<cfif isDefined("CFFILE.serverFile")>
<cfset session.slot = cffile.serverFile>
<cfelse>
<cfset form.storage = "">
</cfif>
</cfif>
<body>
<label class="control-label" for="b1b3formAttach">Attach the completed B1/B3 Form*</label></br>
<div class="controls">
<input id="b1b3formAttach" name="b1b3formAttach" class="input-file" type="file">
</div>
<div class="controls">
<button value="Submit" type="submit" id="Submit" name="Submit" class="btn btn-default">Submit</button>
</div>
</body>
错误简要说明:
The form field b1b3formAttach did not contain a file.
The error occurred in C:/ColdFusion11/cfusion/wwwroot/wwwroot/form.cfm: line 21
19 : fileField = "b1b3formAttach"
20 : destination = "#GetTempDirectory()#"
21 : nameConflict = "overwrite">
22 : <cfif isDefined("CFFILE.serverFile")>
23 : <cfset form.storage = cffile.serverFile>
验证输入是否包含文件的理想方法是什么?