0

Here is a basic cffile upload with makeUnique:

<cffile action = "upload"
    destination   = "#session.exploc#"
    fileField     = "form.theupload"
    mode          = '666'
    accept        = 'html'
    strict        = 'true'
    result        = 'ss'
    nameConflict  = "makeUnique">

When I upload a file with the same name as an existing file, I am able to pick up the new name this way:

<cfset name    = ss.ServerFileName>

I uploaded the file worl1.html several times and got names worl,worl12,worl13, etc. Then I logged out of the application and came back a bit later.

When I again uploaded worl1.html I got an error saying the the file worl12 already exists. So evidently makeUnique only checks once, and does not check for subsequent versions of this file.

Coding around this seems like a pain. I would have to upload each file to a dummy location, then check myself if it exists in the real location and rename it if necessary. Then I'll have to remove the file from the dummy location in case the next one is a conflict.

Can anyone suggest a way to solve this problem simply without a lot of extra code. At the least I need to trap the error and give the user a message he can understand. But trapping the actual problem and fixing it would be better. I need it to work in ColdFusion 10, but it would be nice if it also works in Lucee.

Betty Mock
  • 1,373
  • 11
  • 23
  • Here's someone else who experienced a similar issue to yours. http://www.justskins.com/forums/cffile-upload-makeunique-not-125009.html Although he figured out what is causing his issue, he didn't provide a solution. To me, it sounds like a bug with the `makeUnique` option. Anyhow, a simple fix to your issue would be to just append a date and timestamp to the filename on every upload, therefore guaranteeing a unique filename every time. – user12031119 Mar 11 '20 at 07:10
  • Another option for you is to use this already written UDF at https://cflib.org/udf/uploadFile which has robust name conflict handling precoded for you. – user12031119 Mar 11 '20 at 14:18
  • The UDF seems to have been thought through very well. I can do the date/time thing, but it makes it hard for the user to identify the file for retrieval; and my code is not at thorough as in the UFD. You've been most helpful. – Betty Mock Mar 11 '20 at 19:36

0 Answers0