• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

CFFILE Question on Railo & Windows servers

Participant ,
Jun 06, 2019 Jun 06, 2019

Copy link to clipboard

Copied

I have this code

<cfif len(trim(form.fileUpload))>

  <cffile action="upload"

     fileField="fileUpload"

     destination="#FileDirectory#"

     nameconflict="makeunique">

  <cfset FileName ="#FORM.lname#_#FORM.file_type#_#FORM.key#">

  <cffile action="rename" source="#FileDirectory##cffile.serverfile#" destination="#FileDirectory##variables.filename#-0.#cffile.serverFileExt#" nameconflict="makeunique">

</cfif>

It is code where users upload files and they get uploaded. If there are files with the same name they get renamed and made unique.

For example

Upload 1 = REV-D_166032-0.docx
Upload 2 = REV-D_166032-01.docx

Upload 3 = REV-D_166032-02.docx

I have this on a Railo server and it works fine.

But I have the exact same code on a windows server and it works differently.

It overwrites the existing file. Like this

Upload 1 = REV-D_166032-0.docx
Upload 2 = REV-D_166032-0.docx

Upload 3 = REV-D_166032-0.docx

Is there some server setting on the windows server that I need to change?
Is there some change in the code I need to make?

Views

943

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jun 06, 2019 Jun 06, 2019

From your description, the following code is sufficient:

<cfif len(trim(form.fileUpload)) gt 0>

  <cffile action="upload"

    fileField="fileUpload"

    destination="#FileDirectory#"

    nameconflict="makeunique">

</cfif>

Votes

Translate

Translate
LEGEND ,
Jun 06, 2019 Jun 06, 2019

Copy link to clipboard

Copied

I'm not aware of any settings that can be changed in the Windows server that would mimic how the Railo server handles unique filenames.  I know that if you _copy_ a file in Windows and try to paste it into the same folder, Windows will prepend "Copy of " to the filename.  But I think CF is intervening before Windows can do that.  There _might_ be a setting in CFAdmin?????  I'm really not sure, as I'm not really a CF Administrator.

HTH,

^ _ ^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jun 06, 2019 Jun 06, 2019

Copy link to clipboard

Copied

If you use the "makeunique" setting of the nameconflict parameter then you need to use the result of the cffile tag to get the name that ColdFusion used to make the file unique. Currently your code is assuming that the "upload" action did not rename the file.

Also, the nameconflict parameter is not used for the "rename" action. You should remove it to avoid confusion.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 06, 2019 Jun 06, 2019

Copy link to clipboard

Copied

LATEST

From your description, the following code is sufficient:

<cfif len(trim(form.fileUpload)) gt 0>

  <cffile action="upload"

    fileField="fileUpload"

    destination="#FileDirectory#"

    nameconflict="makeunique">

</cfif>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation