Skip to content

Commit 4af6dfa

Browse files
committed
Improve extension handling
1 parent ea8816f commit 4af6dfa

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

src/Entities/File.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,21 +67,24 @@ public function getPath(): string
6767
*/
6868
public function getExtension($method = ''): string
6969
{
70-
if (! $method || $method === 'type')
70+
if ($this->attributes['type'] !== 'application/octet-stream')
7171
{
72-
if ($extension = Mimes::guessExtensionFromType($this->attributes['type']))
72+
if (! $method || $method === 'type')
7373
{
74-
return $extension;
74+
if ($extension = Mimes::guessExtensionFromType($this->attributes['type']))
75+
{
76+
return $extension;
77+
}
7578
}
76-
}
7779

78-
if (! $method || $method === 'mime')
79-
{
80-
if ($file = $this->getObject())
80+
if (! $method || $method === 'mime')
8181
{
82-
if ($extension = $file->guessExtension())
82+
if ($file = $this->getObject())
8383
{
84-
return $extension;
84+
if ($extension = $file->guessExtension())
85+
{
86+
return $extension;
87+
}
8588
}
8689
}
8790
}

src/Models/FileModel.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use CodeIgniter\Files\File as CIFile;
44
use CodeIgniter\Model;
5+
use Config\Mimes;
56
use Tatter\Files\Entities\File;
67
use Tatter\Files\Exceptions\FilesException;
78
use Tatter\Thumbnails\Exceptions\ThumbnailsException;
@@ -151,7 +152,7 @@ public function createFromFile(CIFile $file, array $data = []): File
151152
'filename' => $file->getFilename(),
152153
'localname' => $file->getRandomName(),
153154
'clientname' => $file->getFilename(),
154-
'type' => $file->getMimeType(),
155+
'type' => Mimes::guessTypeFromExtension($file->getExtension()) ?? $file->getMimeType(),
155156
'size' => $file->getSize(),
156157
];
157158

0 commit comments

Comments
 (0)