I'm doing a cffile upload, and want to trap any errors in the MIME type. I wrote this code:
<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>
When I try to upload a wrong MIME type, it does not load, which is good. The form is submitting which is not good but I'll deal with that later. My problem now is I have been unable to get a message about the error to show up anywhere. I have tried the following:
<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#"
I have tried all these inside and outside of the cfcatch tag, but always within the cftry tag. All of these approaches were in the research I did, but none of them are working for me.
Can anyone tell me what I am doing wrong here?