|
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 | * |
@@ -106,16 +100,19 @@ private function uploadValidator($file) |
106 | 100 | $file_size = $file->getSize() / 1000; |
107 | 101 | $type_key = $this->currentLfmType(); |
108 | 102 |
|
109 | | - $mine_config = 'lfm.valid_' . $type_key . '_mimetypes'; |
110 | | - $valid_mimetypes = config($mine_config, $this->{"default_{$type_key}_types"}); |
111 | | - $max_size = config('lfm.max_' . $type_key . '_size', $this->{"default_max_{$type_key}_size"}); |
112 | | - |
113 | | - if (false === in_array($mimetype, $valid_mimetypes)) { |
114 | | - return $this->error('mime') . $mimetype; |
| 103 | + if (config('lfm.should_validate_mime')) { |
| 104 | + $mine_config = 'lfm.valid_' . $type_key . '_mimetypes'; |
| 105 | + $valid_mimetypes = config($mine_config, []); |
| 106 | + if (false === in_array($mimetype, $valid_mimetypes)) { |
| 107 | + return $this->error('mime') . $mimetype; |
| 108 | + } |
115 | 109 | } |
116 | 110 |
|
117 | | - if ($file_size > $max_size) { |
118 | | - return $this->error('size') . $mimetype; |
| 111 | + if (config('lfm.should_validate_size')) { |
| 112 | + $max_size = config('lfm.max_' . $type_key . '_size', 0); |
| 113 | + if ($file_size > $max_size) { |
| 114 | + return $this->error('size') . $mimetype; |
| 115 | + } |
119 | 116 | } |
120 | 117 |
|
121 | 118 | return 'pass'; |
|
0 commit comments