Highlighted

CFFILE Question on Railo & Windows servers

Participant ,
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?

Adobe Community Professional
Correct answer by BKBK | Adobe Community Professional

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>

Views

796

Likes

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

CFFILE Question on Railo & Windows servers

Participant ,
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?

Adobe Community Professional
Correct answer by BKBK | Adobe Community Professional

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>

Views

797

Likes

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
Jun 06, 2019 0
LEGEND ,
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,

^ _ ^

Likes

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
Reply
Loading...
Jun 06, 2019 0
Advocate ,
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.

Likes

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
Reply
Loading...
Jun 06, 2019 1
Adobe Community Professional ,
Jun 06, 2019

Copy link to clipboard

Copied

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>

Likes

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
Reply
Loading...
Jun 06, 2019 0