Server side validation for file type with cffil sent via cfmail problem
Hello;
I have a small app that I need to allow users to be able to use a form, and send me and email with a file attachment. I have it working nicely, I included file manipulation into the validation process of the form and required form fields. The problem I'm having, is this. I'm trying to create and instance where if they try and upload lets say a pdf, it throws and error: "You are trying to upload the wrong file, please try again we only accept bla bla bla" Problem is, even if I'm uploading the proper file, it's rejecting it and deleting it. Can someone help me fix this? I've tried a number of different ways and can't seem to get this to go off properly. I am posting some of the code. There is a ton, so I'm posting the main parts so you get the idea and see my variables.
<!--- Declairing my variables and setting up form validation--->
<cfparam name="FORM.descript" type="string" default=""/>
<cfparam name="FORM.attachment_1" type="string" default=""/>
<cfset arrErrors = ArrayNew( 1 ) />
<cfset showForm = true>
<cfif structKeyExists(form, "sendcomments")>
<cfif NOT len(trim(FORM.name))>
<cfset ArrayAppend(arrErrors,"Your Full Name!<br>") />
</cfif>
<!--- This is where the file error control is as you can see how the name is validated, the file will be dealt with in a similar maner--->
<cfif NOT Len(Trim(FORM.attachment_1))>
<cfset ArrayAppend(arrErrors,"You didn't attach a file!<br>") />
<cfelseif ArrayLen( arrErrors )>
<cftry>
<cffile action="DELETE" file="#FORM.resume#"/>
<cfcatch>
<!--- File delete error. --->
</cfcatch>
</cftry>
<cfelse>
<!--- no errors with the file upload so lets upload it--->
<cftry>
<cfset request.AcceptImage="image/gif,image/jpg,image/jpeg,image/pjpeg,image/x-png">
<cffile action="upload"
filefield="attachment_1"
accept="#request.AcceptImage#"
destination="c:\websites\187914Kg3\uploads\"
nameconflict="Makeunique">
<!---
Now that we have the file uploaded, let's
check the file extension. I find this to be
better than checking the MIME type as that
can be inaccurate (so can this, but at least
it doesn't throw a ColdFusion error).
--->
<cfif NOT ListFindNoCase("request.AcceptImage",CFFILE.ServerFileExt)>
<cfset ArrayAppend(arrErrors,"Only JPEG, GIF, and PNG file formats are accepted!<br>") />
<!---
Since this was not an acceptable file,
let's delete the one that was uploaded.
--->
<cftry>
<cffile action="DELETE" file="#CFFILE.ServerDirectory#\#CFFILE.ServerFile#"/>
<cfcatch>
<!--- File Delete Error. --->
</cfcatch>
</cftry>
</cfif>
<!--- This is the code that is causing my problem. The above code is saying everything is not the proper file and rejecting it all--->
Can anyone help me out. I can make more of this code available if needed. Like i said, there's a lot and I didn't want to dump it all out, this is the section creating the problem. There are no errors at this time, just rejecting all file types.
thank you.
