From f068541ab40f7f045b97171ca935e5c5528d2d46 Mon Sep 17 00:00:00 2001 From: Dasun Tharanga Date: Fri, 5 Apr 2024 18:20:02 +0530 Subject: [PATCH] fix: Handle the file removal event without manually deleting files (#24) --- src/Http/Livewire/Dropzone.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/Http/Livewire/Dropzone.php b/src/Http/Livewire/Dropzone.php index 73ddf24..dc6fdd2 100644 --- a/src/Http/Livewire/Dropzone.php +++ b/src/Http/Livewire/Dropzone.php @@ -104,13 +104,11 @@ public function onFileAdded(array $file): void public function onFileRemoved(string $tmpFilename): void { $this->files = array_filter($this->files, function ($file) use ($tmpFilename) { - $isNotTmpFilename = $file['tmpFilename'] !== $tmpFilename; - - if (! $isNotTmpFilename) { - unlink($file['path']); - } - - return $isNotTmpFilename; + // Remove the temporary file from the array only. + // No need to remove from the Livewire's temporary upload directory manually. + // Because, files older than 24 hours cleanup automatically by Livewire. + // For more details, refer to: https://livewire.laravel.com/docs/uploads#configuring-automatic-file-cleanup + return $file['tmpFilename'] !== $tmpFilename; }); }