Skip to content

Commit 283155c

Browse files
author
ChenCatherine
committed
Make mime type and file size be optional, setting non-validated as default.
1 parent 376ad24 commit 283155c

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
*
@@ -100,16 +94,19 @@ private function uploadValidator($file)
10094
$file_size = $file->getSize() / 1000;
10195
$type_key = $this->currentLfmType();
10296

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+
}
109103
}
110104

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+
}
113110
}
114111

115112
return 'pass';

0 commit comments

Comments
 (0)