uploading a file, renaming it and placing it in a particular location on server
A user submits a file from a front end HTML form which has fields like Division, Department name, department number,
section number, year, email, phone etc. The file being submitted might have a user given name. But, when it is
uploaded I want it to be named as Departmentname_departmentnumber_sectionnumber. So, if department is Accounting,
dept number is 123 and section is 1, name of file will be Accounting_123_1.doc The extension will be whatever type
of file(text, MS-Word's .doc or .docx, PDF or RTF) was submitted and the user can upload attachments of files with
extension .txt, .doc, .docx, pdf, rtf only.
Also, I want it to be stored on a particular location on server. So, if Division is Corporate Finance and year is
2011-2012 it should be stored on server at "E:\Files Submitted\2011-2012\Corporate Finance\". The "E:\Files
Submitted\" part remains same in the directory name.
<cfset submittedfileName =
#form.departmentname#&"_"&#form.departmentnumber#&"_"&#form.section_number_1#&"."&#cffile.ClientFileExt#>
<cfset filedirectoryYear = "E:\Files Submitted\"&#form.current_year#&"\"&#form.division#&"\">
<!--- ensure that the user uploads attachments of type with extension .txt, .doc, .docx, pdf, rtf only--->
<cfif FORM.attachment_1 neq "">
<cffile action="upload"
accept="text/plain,application/msword,application/pdf,application/rtf"
filefield="attachment_1"
destination="E:\temp\uploads"
nameconflict="Makeunique"
>
<!--- rename the file and move it to permanent destination --->
<cffile
action="rename"
source="E:\temp\uploads\#cffile.serverFileName#"
destination=#filedirectoryYear#&#submittedfileName#&#cffile.ClientFileExt#
>
<!--- now create a temporary variable for the attachment so that it can be emailed later on --->
<cfset attachment_local_file_1 = #filedirectoryYear#&#submittedfileName#&#cffile.ClientFileExt#>
</cfif>
I used the cffile.ClientFileExt because the files were getting uploaded without the extension but am receiving an
error at destination=#filedirectoryYear#&#submittedfileName#&#cffile.ClientFileExt# as "multiple items at this
position: Missing Token > or /> .
I am using Coldfusion 8. Any suggestions would be appreciated on where I am erring and how I can fix it.
