【发布时间】:2020-03-12 20:50:55
【问题描述】:
我正在上传 cffile,并且想要捕获 MIME 类型中的任何错误。我写了这段代码:
<form
enctype= "multipart/form-data"
method = "post"
name = "templupload"
action = "frag2.cfm">
<cftry>
<cffile action = "upload"
destination = "#session.exploc#"
fileField = "form.theupload"
mode = '666'
accept = 'html'
strict = 'true'
result = 'ss'
nameConflict = "Overwrite">
<!--- bad mime type files --->
<cfcatch type = 'any'>
<cfif FindNoCase("The MIME type or the Extension of the uploaded file", cfcatch.message)>
<cfoutput>
<script>
document.getElementById('tmpl').innerHTML = "error";
</script>
</cfoutput>
</cfif>
</cfcatch>
<cfthrow type="any" message="got an error" />
</cftry>
当我尝试上传错误的 MIME 类型时,它不会加载,这很好。表单正在提交,这不好,但我稍后会处理。我现在的问题是我无法在任何地方收到有关错误的消息。我尝试了以下方法:
<cfcatch.message = 'error';
<script>alert('error');</script>
<script> document.getElementById('tmpl').innerHTML = "error";</script>
<!--- this 2nd script does not work regardless of whether the tmpl
id is on the original page or the target page --->
<cfoutput> error </cfoutput>
<p> error </p>
<cfthrow type = 'any' message = 'error' />
<cfdump var = "#catch#" or var = '#catch.message#"
我已经在 cfcatch 标记内外尝试了所有这些,但总是在 cftry 标记内。所有这些方法都在我所做的研究中,但没有一个对我有用。
谁能告诉我我在这里做错了什么?
【问题讨论】:
标签: coldfusion try-catch cfml