I am re-posting the issue related to when uploading multiple files it creates duplicate & orphaned files on the server.

The original bug was posted here (#348697).

Here is screencast using the most recent version of FileField and CCK download from the CVS repository.

I know this is a very tricky bug and I hope this screencast helps you resolve it. I really appreciate all the work you have done.


Members fund testing for the Drupal project. Drupal Association Learn more


dopry’s picture

Dude! What an awesome way to demonstrate a bug! You're right its a completely critical issue.

Can you check if the status for the unassociated files is 0 after saving the node, if you still have the site setup?

I hope it's 0, then they'll at least be deleted by the files garbage collection cron job.

Regardless, if it's a lot of large files that are uploaded in duplicates like that it really slows down the responsiveness.

I'm not sure that I can get to this in the next few days, but it is definitely high on my list of bugs to fix next... I'd welcome patches if anyone else has time to look into the issue.

jrockowitz’s picture

Yes the unassociated files have their status set to 0. (see attached)

quicksketch’s picture

Yep, I have to agree, this is a very nice bug report. :)

It's likely that we'll run into a browser limitation here. It's not possible to submit just part of a form, you have to submit the entire thing every time, so each time you clicked "Upload" you were uploading all 5 files to the server. This could be a pretty big problem if you were uploading several very large files.

Since we can't really avoid this behavior, we could pursue a different route and provide only a single upload button, rather than one for each field. However, this brings up all kinds of other difficulties, especially since we want to capitalize on the progress CCK multifield is making that allows you to combine multiple fields into a multivalue field.

So.... seems like our option might be to save all the uploaded files even if you only click one of the upload buttons.

Or... as a last option, let the user upload all the files every time, but delete the files from disk immediately that were not wanted.

Like Dopry says, at the very least we can appreciate that the status is 0 for these files, so they would get cleaned up eventually.

quicksketch’s picture

Status: Active » Needs review
1.53 KB

Here's a patch which should solve the problem but could use a bit more testing. I found that it actually *is* possible to omit certain parts of the form by setting fields to "disabled". This excludes them from being sent in the POST request. So with a little additional JavaScript, we can make it so that buttons don't accidentally upload filefields for which they are not responsible.

I found this problem exists for all the CCK "more" buttons, so I wrote this so that it will run on all AHAH enabled buttons. In the current FileField, you can populate any FileField on the page, then click any "more" button provided by CCK and we have the same problem. The more button can even be provided by textfields and still cause uploads.

Please try it out and let me know if it helps with the problem and any problems you might experience with it.

quicksketch’s picture

Status: Needs review » Fixed

I've committed this patch since it's a pretty critical problem and I couldn't find any negative side-effects. Works on Safari, Firefox, IE 6/7, so we're pretty good in the browser compatibility.

jrockowitz’s picture

Status: Fixed » Needs work
861 bytes
1.26 KB

Thanks for working on this issue.

The solution you came up with is a great idea. When I re-tested this issue, I am still getting the same problem with all the files being uploaded which then creates duplicate files on the server.

The easiest way to duplicate the exact problem, in IE/Win and FF/Linux, is to...
- Create an unlimited file field input which by default will have two visible file upload inputs.
- Browse and add a file to each of the file upload inputs.
- Click upload on the first file field input.
- Then click upload on the second file field input.

The second file field's file name will be appended with an '_0'

Looking over the patch I figured out that the Drupal.behaviors.filefieldButtons function was not initially adding the mousedown event handler most likely because the behavior was being executed before the ahah processing behavior function.

One solution would be to apply mousedown handler to all $('.input.form-submit') and then check for 'ahah-processed' class name.

I also noticed that the re-enable 1 millisecond timeout for the file upload inputs was not working for me so I changed it be 1000 milliseconds which visibly disables the file upload inputs but works. A guess would be the form submission event handler is using a different event, like onclick or onsubmit, and not occurring within the same JS call.

Attached is a patch that contains both the above solutions. It is my first attempt at any patch, so if there are any problems please tell me and I will fix them. I am not fully up to speed with Drupal.behaviors and AHAH processing so there is probably a better solution to this problem.

Thanks again.

quicksketch’s picture

Status: Needs work » Fixed

Thanks, yeah 1ms might've been cutting it close. I figured I might be able to out-clever the JS parsers. The form.jquery.js library has an intentional 500ms delay right in the middle of it to give the browser a rest before submitting. I think the 1000ms is much safer, even though it has a small visual side-effect.

I committed your "tweak" patch from above. Thanks! Please let me know if you can find any more problems.

jrockowitz’s picture

Thanks for fixing the issue and thanks for committing my first (and not last) patch.

It made me smile.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.