Skip to content

Commit 040e376

Browse files
committed
Prevalidate thumbnail extensions
1 parent a99cb00 commit 040e376

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

src/Models/FileModel.php

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -178,28 +178,33 @@ public function createFromFile(CIFile $file, array $data = []): File
178178
{
179179
$this->addToUser($fileId, $userId);
180180
}
181-
182-
// Try to create a Thumbnail
183-
$thumbnail = pathinfo($row['localname'], PATHINFO_FILENAME);
184-
$output = $storage . 'thumbnails' . DIRECTORY_SEPARATOR . $thumbnail;
185-
186-
try
181+
182+
// Check for a thumbnail handler
183+
$extension = pathinfo((string) $file, PATHINFO_EXTENSION);
184+
if (service('thumbnails')->matchHandlers($extension) !== [])
187185
{
188-
service('thumbnails')->create((string) $file, $output);
186+
// Try to create a Thumbnail
187+
$thumbnail = pathinfo($row['localname'], PATHINFO_FILENAME);
188+
$output = $storage . 'thumbnails' . DIRECTORY_SEPARATOR . $thumbnail;
189189

190-
// If it succeeds then update the database
191-
$this->update($fileId, [
192-
'thumbnail' => $thumbnail,
193-
]);
194-
}
195-
catch (\Throwable $e)
196-
{
197-
log_message('error', $e->getMessage());
198-
log_message('error', 'Unable to create thumbnail for ' . $row['filename']);
190+
try
191+
{
192+
service('thumbnails')->create((string) $file, $output);
199193

200-
if (ENVIRONMENT === 'testing')
194+
// If it succeeds then update the database
195+
$this->update($fileId, [
196+
'thumbnail' => $thumbnail,
197+
]);
198+
}
199+
catch (\Throwable $e)
201200
{
202-
throw $e;
201+
log_message('error', $e->getMessage());
202+
log_message('error', 'Unable to create thumbnail for ' . $row['filename']);
203+
204+
if (ENVIRONMENT === 'testing')
205+
{
206+
throw $e;
207+
}
203208
}
204209
}
205210

0 commit comments

Comments
 (0)