|
12 | 12 | */ |
13 | 13 | class UploadController extends LfmController |
14 | 14 | { |
15 | | - private $default_file_types = ['application/pdf']; |
16 | | - private $default_image_types = ['image/jpeg', 'image/png', 'image/gif']; |
17 | | - // unit is assumed to be kb |
18 | | - private $default_max_file_size = 1000; |
19 | | - private $default_max_image_size = 500; |
20 | | - |
21 | 15 | /** |
22 | 16 | * Upload an image/file and (for images) create thumbnail |
23 | 17 | * |
@@ -100,16 +94,19 @@ private function uploadValidator($file) |
100 | 94 | $file_size = $file->getSize() / 1000; |
101 | 95 | $type_key = $this->currentLfmType(); |
102 | 96 |
|
103 | | - $mine_config = 'lfm.valid_' . $type_key . '_mimetypes'; |
104 | | - $valid_mimetypes = config($mine_config, $this->{"default_{$type_key}_types"}); |
105 | | - $max_size = config('lfm.max_' . $type_key . '_size', $this->{"default_max_{$type_key}_size"}); |
106 | | - |
107 | | - if (false === in_array($mimetype, $valid_mimetypes)) { |
108 | | - return $this->error('mime') . $mimetype; |
| 97 | + if (config('lfm.should_validate_mime')) { |
| 98 | + $mine_config = 'lfm.valid_' . $type_key . '_mimetypes'; |
| 99 | + $valid_mimetypes = config($mine_config, []); |
| 100 | + if (false === in_array($mimetype, $valid_mimetypes)) { |
| 101 | + return $this->error('mime') . $mimetype; |
| 102 | + } |
109 | 103 | } |
110 | 104 |
|
111 | | - if ($file_size > $max_size) { |
112 | | - return $this->error('size') . $mimetype; |
| 105 | + if (config('lfm.should_validate_size')) { |
| 106 | + $max_size = config('lfm.max_' . $type_key . '_size', 0); |
| 107 | + if ($file_size > $max_size) { |
| 108 | + return $this->error('size') . $mimetype; |
| 109 | + } |
113 | 110 | } |
114 | 111 |
|
115 | 112 | return 'pass'; |
|
0 commit comments