numero2 / contao-proper-filenames

Replaces special characters in filenames right after upload.
https://www.numero2.de/contao/erweiterungen/proper-filenames.html
GNU Lesser General Public License v3.0
13 stars 5 forks source link

Auto-renaming of duplicate file names does not work when filename is sanitized #13

Closed fritzmg closed 3 years ago

fritzmg commented 3 years ago

If you enable the options Store uploaded files and Preserve existing files (and do not disable Do not check/rename uploaded files) and then upload a file with illegal characters in its name (which are then sanitised) twice or more, the uploaded files do not get automatically renamed anymore.

bennyborn commented 3 years ago

[...] and do not disable Do not check/rename uploaded files [...] uploaded files do not get automatically renamed anymore.

Did I understand you correctly? So you mean Do not check/rename uploaded files should be checked - like this?

image

If so renaming seems to work just fine in my local 4.9.21

image

fritzmg commented 3 years ago

Did I understand you correctly? So you mean Do not check/rename uploaded files should be checked - like this?

No, it should not be checked, i.e. the sanitation should not be disabled. The issue only occurs when sanitation is not disabled.

bennyborn commented 3 years ago

Ah okay, got it.

Hmm it seems like we'd need to take care of doNotOverwrite ourself.

fritzmg commented 3 years ago

Hmm it seems like we'd need to take care of doNotOverwrite ourself.

Hm, may be you could also use the loadFormField hook instead. In there you could check additionally for

if (Input::post('FORM_SUBMIT') !== $formId) {
    return $objWidget;
}

And then you would manipulate $_FILES[$objWidget->name] instead of $_SESSION['FILES'][$objWidget->name]. Then afterwards FormFileUpload::validate would work as usual and take care of everything.

bennyborn commented 3 years ago

Hm, may be you could also use the loadFormField hook instead.

Ah, love the "out of the box thinking"! Seems to work even better and saves us so much trouble :) Implemented in 713d3748edf1cc3df20c875073108a05e3a5e2bf

fritzmg commented 3 years ago

Implemented in 713d374

Tested and works great so far 👍

bennyborn commented 3 years ago

Implemented in 713d374

Tested and works great so far 👍

Thanks for your help!