SpatieMediaLibrary Image upload weirdness
I am building a user maintenance form which includes the ability to upload 3 profile images. The image uploads are handled using the SpatieMediaLibrary form control.
The control seems okay when new images are added in that the media table is populated and the files are saved to disk fine. However if (for example) there are 3 images already uploaded and 1 image is deleted from the collection then when the form is saved all the images get deleted from storage but the 2 media database table entries remain which point to non-existent files. So Is there something I've missed here?
The control seems okay when new images are added in that the media table is populated and the files are saved to disk fine. However if (for example) there are 3 images already uploaded and 1 image is deleted from the collection then when the form is saved all the images get deleted from storage but the 2 media database table entries remain which point to non-existent files. So Is there something I've missed here?
Solution
Thanks - have done that and it made no difference.
However I drilled down into the plugin code and found the reason. When an image is deleted from a collection the
Sorry for the noise!
However I drilled down into the plugin code and found the reason. When an image is deleted from a collection the
Spatie\MediaLibrary\MediaCollections\Filesystem class method removeAllFiles() gets called. As you would expect this call will remove all files in the directory where the uploaded file is stored. In this case the media path generator had placed all the profile images for a user in the same directory so all files got zapped when only a single delete was needed. So this was an implementation bug not an issue with Fil or SML plugin.Sorry for the noise!