|
1 | 1 | <?php namespace Tatter\Files\Controllers; |
2 | 2 |
|
3 | 3 | use CodeIgniter\Controller; |
4 | | -use CodeIgniter\Files\File; |
| 4 | +use CodeIgniter\Exceptions\PageNotFoundException; |
5 | 5 | use CodeIgniter\HTTP\RedirectResponse; |
6 | 6 | use CodeIgniter\HTTP\RequestInterface; |
7 | 7 | use CodeIgniter\HTTP\ResponseInterface; |
8 | 8 | use Psr\Log\LoggerInterface; |
9 | 9 | use Tatter\Files\Config\Files as FilesConfig; |
10 | 10 | use Tatter\Files\Exceptions\FilesException; |
| 11 | +use Tatter\Files\Entities\File; |
11 | 12 | use Tatter\Files\Models\FileModel; |
12 | 13 |
|
13 | 14 | class Files extends Controller |
@@ -512,11 +513,18 @@ public function export(string $slug, $fileId): ResponseInterface |
512 | 513 | * |
513 | 514 | * @return ResponseInterface |
514 | 515 | */ |
515 | | - public function thumbnail($fileId) |
| 516 | + public function thumbnail($fileId): ResponseInterface |
516 | 517 | { |
517 | | - $file = $this->model->find($fileId); |
518 | | - $data = $file->getThumbnail('raw'); |
519 | | - return $this->response->setHeader('Content-type', 'image/jpeg')->setBody($data); |
| 518 | + if ($file = $this->model->find($fileId)) |
| 519 | + { |
| 520 | + $path = $file->getThumbnail(); |
| 521 | + } |
| 522 | + else |
| 523 | + { |
| 524 | + $path = File::locateDefaultThumbnail(); |
| 525 | + } |
| 526 | + |
| 527 | + return $this->response->setHeader('Content-type', 'image/jpeg')->setBody(file_get_contents($path)); |
520 | 528 | } |
521 | 529 |
|
522 | 530 | //-------------------------------------------------------------------- |
|
0 commit comments