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










0















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 Submitted2011-2012Corporate 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:tempuploads"
nameconflict="Makeunique"
>

<!--- rename the file and move it to permanent destination --->
<cffile action="rename"
source="E:tempuploads#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.










share|improve this question
























  • FYI it is not necessary to enclose every variable in ## everywhere in your code. This is perfectly fine: <cfset filedirectoryYear = "E:Files Submitted" & form.current_year & "" & form.division & ""> and more readable, too.

    – Tomalak
    Oct 7 '11 at 14:59












  • Also, do not depend on mime type checks for security petefreitag.com/item/701.cfm

    – Leigh
    Oct 7 '11 at 16:01















0















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 Submitted2011-2012Corporate 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:tempuploads"
nameconflict="Makeunique"
>

<!--- rename the file and move it to permanent destination --->
<cffile action="rename"
source="E:tempuploads#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.










share|improve this question
























  • FYI it is not necessary to enclose every variable in ## everywhere in your code. This is perfectly fine: <cfset filedirectoryYear = "E:Files Submitted" & form.current_year & "" & form.division & ""> and more readable, too.

    – Tomalak
    Oct 7 '11 at 14:59












  • Also, do not depend on mime type checks for security petefreitag.com/item/701.cfm

    – Leigh
    Oct 7 '11 at 16:01













0












0








0








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 Submitted2011-2012Corporate 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:tempuploads"
nameconflict="Makeunique"
>

<!--- rename the file and move it to permanent destination --->
<cffile action="rename"
source="E:tempuploads#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.










share|improve this question
















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 Submitted2011-2012Corporate 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:tempuploads"
nameconflict="Makeunique"
>

<!--- rename the file and move it to permanent destination --->
<cffile action="rename"
source="E:tempuploads#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.







coldfusion






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Oct 7 '11 at 14:56









Tomalak

257k51425541




257k51425541










asked Oct 7 '11 at 14:47









Mike JMike J

1125




1125












  • FYI it is not necessary to enclose every variable in ## everywhere in your code. This is perfectly fine: <cfset filedirectoryYear = "E:Files Submitted" & form.current_year & "" & form.division & ""> and more readable, too.

    – Tomalak
    Oct 7 '11 at 14:59












  • Also, do not depend on mime type checks for security petefreitag.com/item/701.cfm

    – Leigh
    Oct 7 '11 at 16:01

















  • FYI it is not necessary to enclose every variable in ## everywhere in your code. This is perfectly fine: <cfset filedirectoryYear = "E:Files Submitted" & form.current_year & "" & form.division & ""> and more readable, too.

    – Tomalak
    Oct 7 '11 at 14:59












  • Also, do not depend on mime type checks for security petefreitag.com/item/701.cfm

    – Leigh
    Oct 7 '11 at 16:01
















FYI it is not necessary to enclose every variable in ## everywhere in your code. This is perfectly fine: <cfset filedirectoryYear = "E:Files Submitted" & form.current_year & "" & form.division & ""> and more readable, too.

– Tomalak
Oct 7 '11 at 14:59






FYI it is not necessary to enclose every variable in ## everywhere in your code. This is perfectly fine: <cfset filedirectoryYear = "E:Files Submitted" & form.current_year & "" & form.division & ""> and more readable, too.

– Tomalak
Oct 7 '11 at 14:59














Also, do not depend on mime type checks for security petefreitag.com/item/701.cfm

– Leigh
Oct 7 '11 at 16:01





Also, do not depend on mime type checks for security petefreitag.com/item/701.cfm

– Leigh
Oct 7 '11 at 16:01












1 Answer
1






active

oldest

votes


















4














The problem is the & in your code. Try this



<cffile 
action="rename"
source="E:tempuploads#cffile.serverFileName#"
destination="#filedirectoryYear##submittedfileName##cffile.ClientFileExt#"
>


String concatenation in ColdFusion either happens through variable interpolation



<cfset foo = "FixedString_#variable#_FixedString">


or as an expression



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


Do not confuse the two.






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f7688897%2fuploading-a-file-renaming-it-and-placing-it-in-a-particular-location-on-server%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    4














    The problem is the & in your code. Try this



    <cffile 
    action="rename"
    source="E:tempuploads#cffile.serverFileName#"
    destination="#filedirectoryYear##submittedfileName##cffile.ClientFileExt#"
    >


    String concatenation in ColdFusion either happens through variable interpolation



    <cfset foo = "FixedString_#variable#_FixedString">


    or as an expression



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


    Do not confuse the two.






    share|improve this answer





























      4














      The problem is the & in your code. Try this



      <cffile 
      action="rename"
      source="E:tempuploads#cffile.serverFileName#"
      destination="#filedirectoryYear##submittedfileName##cffile.ClientFileExt#"
      >


      String concatenation in ColdFusion either happens through variable interpolation



      <cfset foo = "FixedString_#variable#_FixedString">


      or as an expression



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


      Do not confuse the two.






      share|improve this answer



























        4












        4








        4







        The problem is the & in your code. Try this



        <cffile 
        action="rename"
        source="E:tempuploads#cffile.serverFileName#"
        destination="#filedirectoryYear##submittedfileName##cffile.ClientFileExt#"
        >


        String concatenation in ColdFusion either happens through variable interpolation



        <cfset foo = "FixedString_#variable#_FixedString">


        or as an expression



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


        Do not confuse the two.






        share|improve this answer















        The problem is the & in your code. Try this



        <cffile 
        action="rename"
        source="E:tempuploads#cffile.serverFileName#"
        destination="#filedirectoryYear##submittedfileName##cffile.ClientFileExt#"
        >


        String concatenation in ColdFusion either happens through variable interpolation



        <cfset foo = "FixedString_#variable#_FixedString">


        or as an expression



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


        Do not confuse the two.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Oct 7 '11 at 14:57

























        answered Oct 7 '11 at 14:50









        TomalakTomalak

        257k51425541




        257k51425541



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f7688897%2fuploading-a-file-renaming-it-and-placing-it-in-a-particular-location-on-server%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            What does pagestruct do in Eviews?

            Dutch intervention in Lombok and Karangasem

            Channel Islands