Skip to content

Commit b577c12

Browse files
committed
add and apply fileIsImage() in controllers
1 parent e678434 commit b577c12

File tree

5 files changed

+20
-8
lines changed

5 files changed

+20
-8
lines changed

src/controllers/DeleteController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ public function getDelete()
4242
return $this->success_response;
4343
}
4444

45-
File::delete($file_to_delete);
46-
47-
if ($this->isProcessingImages()) {
45+
if ($this->fileIsImage($file_to_delete)) {
4846
File::delete($thumb_to_delete);
4947
}
5048

49+
File::delete($file_to_delete);
50+
5151
event(new ImageWasDeleted($file_to_delete));
5252

5353
return $this->success_response;

src/controllers/ItemsController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ private function getFilesWithInfo($path)
3434
$file_created = filemtime($file);
3535
$file_size = $this->humanFilesize(File::size($file));
3636

37-
if ($this->isProcessingImages()) {
37+
if ($this->fileIsImage($file)) {
3838
$file_type = File::mimeType($file);
3939
$icon = 'fa-image';
4040
} else {

src/controllers/RenameController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ public function getRename()
5555
return $this->success_response;
5656
}
5757

58-
File::move($old_file, $new_file);
59-
60-
if ($this->isProcessingImages()) {
58+
if ($this->fileIsImage($old_file)) {
6159
File::move(parent::getThumbPath($old_name), parent::getThumbPath($new_name));
6260
}
6361

62+
File::move($old_file, $new_file);
63+
6464
event(new ImageWasRenamed($old_file, $new_file));
6565

6666
return $this->success_response;

src/controllers/UploadController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ private function proceedSingleUpload($file)
5555

5656
event(new ImageIsUploading($new_file_path));
5757
try {
58-
if ($this->isProcessingImages()) {
58+
if ($this->fileIsImage($file)) {
5959
Image::make($file->getRealPath())
6060
->orientate() //Apply orientation from exif data
6161
->save($new_file_path, 90);

src/traits/LfmHelpers.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Unisharp\Laravelfilemanager\traits;
44

55
use Illuminate\Support\Facades\File;
6+
use Symfony\Component\HttpFoundation\File\UploadedFile;
67

78
trait LfmHelpers
89
{
@@ -226,6 +227,17 @@ public function directoryIsEmpty($directory_path)
226227
return count(File::allFiles($directory_path)) == 0;
227228
}
228229

230+
public function fileIsImage($file)
231+
{
232+
if ($file instanceof UploadedFile) {
233+
$mime_type = $file->getMimeType();
234+
} else {
235+
$mime_type = File::mimeType($file);
236+
}
237+
238+
return starts_with($mime_type, 'image');
239+
}
240+
229241

230242
/****************************
231243
*** Miscellaneouses ***

0 commit comments

Comments
 (0)