Skip to main content
Inspiring
June 6, 2019
解決済み

CFFILE Question on Railo & Windows servers

  • June 6, 2019
  • 返信数 3.
  • 1128 ビュー

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?

このトピックへの返信は締め切られました。
解決に役立った回答 BKBK

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>

返信数 3

BKBK
Community Expert
BKBKCommunity Expert解決!
Community Expert
June 6, 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>

EddieLotter
Inspiring
June 6, 2019

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.

WolfShade
Legend
June 6, 2019

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,

^ _ ^