I created a few forms for faculty members to nominate colleagues for awards. Many of the nominations require documentation to be submitted in order to validate the nomination. I created one form then modified it to fit the needs of many different award forms. I created it rather hastily and would like input as to how I may trim the fat and make the code more efficient.
One of the forms can be found here. Here's the code relevant to file uploading (starting at line 376 of the paste):
<!---Set file upload destination path to nominationUploads/firstname_lastname--->
<cfset destination = expandPath("./nominationUploads/#fname#_#lname#/")>
<!---If the destination directory does not exist, create it. This will be unique for each nominee.--->
<cfif not directoryExists(destination)>
<cfdirectory action="create" directory="#destination#">
</cfif>
<!---Upload document to the destination. Accept only MSWord, PDF, RTF and plain text files.--->
<cffile action="upload"
filefield="nominationLetter"
accept="application/msword, application/pdf, application/rtf, text/plain, application/vnd.ms-word.document.12, application/vnd.openxmlformats-officedocument.wordprocessingml.document"
destination="#destination#"
nameconflict="makeunique">
<!--- Create variable to reference the original document name and extension uploaded from client.--->
<cfset clientNominationLetter = #file.ClientFile#>
<!---Create variable to reference renamed document. Retain orignal file extension.--->
<cfset renameNomination = "nominationLetter"&"."&#cffile.clientFileExt#>
<!---Rename uploaded document using variable. Save renamed document to original destination.--->
<cffile action="rename"
source="#destination##File.ServerFile#"
destination="#destination##Trim(renameNomination)#">
<!---Upload document to the destination. Accept only MSWord, PDF, RTF and plain text files.--->
<cffile action="upload"
filefield="curriculumVita"
accept="application/msword, application/pdf, application/rtf, text/plain, application/vnd.ms-word.document.12, application/vnd.openxmlformats-officedocument.wordprocessingml.document"
destination="#destination#"
nameconflict="makeunique">
<!--- Create variable to reference the original document name and extension uploaded from client.--->
<cfset clientCurriculumVita = #file.ClientFile#>
<!---Create variable to reference renamed document. Retain orignal file extension.--->
<cfset renameCurriculumVita = "curriculumVita"&"."&#cffile.clientFileExt#>
<!---Rename uploaded document using variable. Save renamed document to original destination.--->
<cffile action="rename"
source="#destination##File.ServerFile#"
destination="#destination##Trim(renameCurriculumVita)#">
<!---Upload document to the destination. Accept only MSWord, PDF, RTF and plain text files.--->
<cffile action="upload"
filefield="recommendation"
accept="application/msword, application/pdf, application/rtf, text/plain, application/vnd.ms-word.document.12, application/vnd.openxmlformats-officedocument.wordprocessingml.document"
destination="#destination#"
nameconflict="makeunique">
<!--- Create variable to reference the original document name and extension uploaded from client.--->
<cfset clientRecommendation = #file.ClientFile#>
<!---Create variable to reference renamed document. Retain orignal file extension.--->
<cfset renameRecommendation = "recommendation"&"."&#cffile.clientFileExt#>
<!---Rename uploaded document using variable. Save renamed document to original destination.--->
<cffile action="rename"
source="#destination##File.ServerFile#"
destination="#destination##Trim(renameRecommendation)#">
<cfif Len(form.recommendation2)>
<!---Upload document to the destination. Accept only MSWord, PDF, RTF and plain text files.--->
<cffile action="upload"
filefield="recommendation2"
accept="application/msword, application/pdf, application/rtf, text/plain, application/vnd.ms-word.document.12, application/vnd.openxmlformats-officedocument.wordprocessingml.document"
destination="#destination#"
nameconflict="makeunique">
<!--- Create variable to reference the original document name and extension uploaded from client.--->
<cfset clientRecommendation2 = #file.ClientFile#>
<!---Create variable to reference renamed document. Retain orignal file extension.--->
<cfset renameRecommendation2 = "recommendation2"&"."&#cffile.clientFileExt#>
<!---Rename uploaded document using variable. Save renamed document to original destination.--->
<cffile action="rename"
source="#destination##File.ServerFile#"
destination="#destination##Trim(renameRecommendation2)#">
</cfif>
<cfif Len(form.recommendation3)>
<!---Upload document to the destination. Accept only MSWord, PDF, RTF and plain text files.--->
<cffile action="upload"
filefield="recommendation3"
accept="application/msword, application/pdf, application/rtf, text/plain, application/vnd.ms-word.document.12, application/vnd.openxmlformats-officedocument.wordprocessingml.document"
destination="#destination#"
nameconflict="makeunique">
<!--- Create variable to reference the original document name and extension uploaded from client.--->
<cfset clientRecommendation3 = #file.ClientFile#>
<!---Create variable to reference renamed document. Retain orignal file extension.--->
<cfset renameRecommendation3 = "recommendation3"&"."&#cffile.clientFileExt#>
<!---Rename uploaded document using variable. Save renamed document to original destination.--->
<cffile action="rename"
source="#destination##File.ServerFile#"
destination="#destination##Trim(renameRecommendation3)#">
</cfif>
<cfif Len(form.recommendation4)>
<!---Upload document to the destination. Accept only MSWord, PDF, RTF and plain text files.--->
<cffile action="upload"
filefield="recommendation4"
accept="application/msword, application/pdf, application/rtf, text/plain, application/vnd.ms-word.document.12, application/vnd.openxmlformats-officedocument.wordprocessingml.document"
destination="#destination#"
nameconflict="makeunique">
<!--- Create variable to reference the original document name and extension uploaded from client.--->
<cfset clientRecommendation4 = #file.ClientFile#>
<!---Create variable to reference renamed document. Retain orignal file extension.--->
<cfset renameRecommendation4 = "recommendation4"&"."&#cffile.clientFileExt#>
<!---Rename uploaded document using variable. Save renamed document to original destination.--->
<cffile action="rename"
source="#destination##File.ServerFile#"
destination="#destination##Trim(renameRecommendation4)#">
</cfif>
<cfif Len(form.recommendation5)>
<!---Upload document to the destination. Accept only MSWord, PDF, RTF and plain text files.--->
<cffile action="upload"
filefield="recommendation5"
accept="application/msword, application/pdf, application/rtf, text/plain, application/vnd.ms-word.document.12, application/vnd.openxmlformats-officedocument.wordprocessingml.document"
destination="#destination#"
nameconflict="makeunique">
<!--- Create variable to reference the original document name and extension uploaded from client.--->
<cfset clientRecommendation5 = #file.ClientFile#>
<!---Create variable to reference renamed document. Retain orignal file extension.--->
<cfset renameRecommendation5 = "recommendation5"&"."&#cffile.clientFileExt#>
<!---Rename uploaded document using variable. Save renamed document to original destination.--->
<cffile action="rename"
source="#destination##File.ServerFile#"
destination="#destination##Trim(renameRecommendation5)#">
</cfif>
<cfif Len(form.recommendation6)>
<!---Upload document to the destination. Accept only MSWord, PDF, RTF and plain text files.--->
<cffile action="upload"
filefield="recommendation6"
accept="application/msword, application/pdf, application/rtf, text/plain, application/vnd.ms-word.document.12, application/vnd.openxmlformats-officedocument.wordprocessingml.document"
destination="#destination#"
nameconflict="makeunique">
<!--- Create variable to reference the original document name and extension uploaded from client.--->
<cfset clientRecommendation6 = #file.ClientFile#>
<!---Create variable to reference renamed document. Retain orignal file extension.--->
<cfset renameRecommendation6 = "recommendation6"&"."&#cffile.clientFileExt#>
<!---Rename uploaded document using variable. Save renamed document to original destination.--->
<cffile action="rename"
source="#destination##File.ServerFile#"
destination="#destination##Trim(renameRecommendation6)#">
</cfif>
</cfif>