-
Notifications
You must be signed in to change notification settings - Fork 517
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to delete a file (not delete entity object and not overwrite with another file)? #323
Comments
I posted too quickly. I solved this with the following code: $this->get('vich_uploader.storage')->remove($entity, 'file_mapping');
$entity->setFile(null);
$entity->setFileName(null); Followed by persisting the entity. |
I close this issue then :) |
I believe this behaviour of not deleting the physical file when an entity object's file variable is set null is rather a bug or a missing feature. I think that with delete_on_update: true setting the variable to null should be captured by the listener and the file should be deleted automatically. |
This should be mentioned in the documentation somewhere :-) |
The bundled evolved and the correct way to remove a file "manually" is now: |
Injection of
|
Does it work like that in 2023? (It seems not) |
Hello,
I'm trying to figure out how to simply delete a file attached to an entity. I do not want to delete the entire entity object and neither do I want to replace the file with another file. Just delete the file. I searched the documentation and tried Google but didn't find anything useful. I also tried to set the file variable of the entity object to NULL and persist the entity. But this did not remove the physical file.
Any hints are highly appreciated.
Best,
Andreas
The text was updated successfully, but these errors were encountered: