Skip to content

Commit 2f45c12

Browse files
author
FreedomKnight
committed
2 parents b0a738b + 283155c commit 2f45c12

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

src/config/lfm.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@
7575
'max_image_size' => 50000,
7676
'max_file_size' => 50000,
7777

78+
'should_validate_mime' => false,
79+
'should_validate_size' => false,
80+
7881
// available since v1.3.0
7982
'valid_image_mimetypes' => [
8083
'image/jpeg',

src/controllers/UploadController.php

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@
1212
*/
1313
class UploadController extends LfmController
1414
{
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-
2115
/**
2216
* Upload an image/file and (for images) create thumbnail
2317
*
@@ -106,16 +100,19 @@ private function uploadValidator($file)
106100
$file_size = $file->getSize() / 1000;
107101
$type_key = $this->currentLfmType();
108102

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+
}
115109
}
116110

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+
}
119116
}
120117

121118
return 'pass';

0 commit comments

Comments
 (0)