uploading a file, renaming it and placing it in a particular location on server using Coldfusion -


a user submits file front end html form has fields division, department name, department number, section number, year, email, phone etc. file being submitted might have user given name. but, when uploaded want named departmentname_departmentnumber_sectionnumber.

so, if department accounting, dept number 123 , section 1, name of file accounting_123_1.doc. extension whatever type of file (text, ms-word's .doc or .docx, pdf or rtf) submitted , user can upload attachments of files extension .txt, .doc, .docx, pdf, rtf only.

also, want stored on particular location on server. so, if division corporate finance , year 2011-2012 should stored on server @ "e:\files submitted\2011-2012\corporate finance\". "e:\files submitted\" part remains same in 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 user uploads attachments of type 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 file , move permanent destination --->            <cffile action="rename"      source="e:\temp\uploads\#cffile.serverfilename#"      destination=#filedirectoryyear#&#submittedfilename#&#cffile.clientfileext#   >    <!--- create temporary variable attachment can emailed later on --->   <cfset attachment_local_file_1 = #filedirectoryyear#&#submittedfilename#&#cffile.clientfileext#>             </cfif> 

i used cffile.clientfileext because files getting uploaded without extension receiving error @ destination=#filedirectoryyear#&#submittedfilename#&#cffile.clientfileext#

"multiple items @ position: missing token > or /> 

i using coldfusion 8. suggestions appreciated on erring , how can fix it.

the problem & in code. try this

<cffile    action="rename"    source="e:\temp\uploads\#cffile.serverfilename#"    destination="#filedirectoryyear##submittedfilename##cffile.clientfileext#" > 

string concatenation in coldfusion either happens through variable interpolation

<cfset foo = "fixedstring_#variable#_fixedstring"> 

or expression

<cfset foo = "fixedstring" & variable & "fixedstring"> 

do not confuse two.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -