| Q | A
|------------ | -----
| Symfony Version | 3.3.*
| VichUploader Bundle Version | 1.6
I'm looking for a way to avoid overwriting a file when the user loads a file with the same name as a file already present and uploaded to the server.
To do this, however, I would like the user not to notice anything, so without changing the name of the file that will be loaded.
I'm trying to do it through the Namers but I do not think there is way.
Practically:
1) the user uploads a file with the same name equal to another file already loaded and present on the server.
2) during loading the original name is changed with a random identifier but all in Back-End. (for example using the symfony UploadedFile)
3) the user will see the file name equal to the loaded one without noticing any difference.
It's possible?
Thank you all.
OrignameNamer is already providing such feature: it adds a uniqid() to client's original name.
Thank's @garak, I solved using both uniqid () saving it in a slug column, and the original name so as to show it to the user. (which at that point will not notice anything)
I close this issue, good work!
File Namer is the solution for this
At the moment there are several available namers:
I personally use HashNamer with MD5:
prodimage:
uri_prefix: /prodimages
upload_destination: '%kernel.project_dir%/public/prodimages'
namer:
service: Vich\UploaderBundle\Naming\HashNamer
options: { algorithm: 'md5', length: 30 }
https://github.com/dustin10/VichUploaderBundle/blob/master/docs/namers.md
Most helpful comment
Thank's @garak, I solved using both uniqid () saving it in a slug column, and the original name so as to show it to the user. (which at that point will not notice anything)
I close this issue, good work!