Skip to content
This repository was archived by the owner on May 22, 2025. It is now read-only.

Commit a0fd463

Browse files
committed
update
- add mime types to ignore to config - omit ext from file rename - cleanup and more consistent with eslint - update rdme
1 parent 9e15e23 commit a0fd463

File tree

8 files changed

+2244
-7196
lines changed

8 files changed

+2244
-7196
lines changed

README.md

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,25 +97,45 @@
9797
// config/mediaManager.php
9898

9999
return [
100-
// ignore files pattern
100+
/*
101+
* ignore files pattern
102+
*/
101103
'ignore_files' => '/^\..*/',
102104

103-
// filesystem disk
105+
/*
106+
* filesystem disk
107+
*/
104108
'storage_disk'=> 'public',
105109

106-
// remove any file special chars except (. _ -)
110+
/*
111+
* remove any file special chars except (. _ -)
112+
*/
107113
'allowed_fileNames_chars'=> '.\_\-',
108114

109-
// remove any folder special chars except (_ -)
110-
'allowed_folderNames_chars'=> '\_\-',
115+
/*
116+
* remove any folder special chars except (_ -)
117+
*/
118+
'allowed_folderNames_chars'=> '\/\_\-',
111119

112-
// when file names gets cleand up
120+
/*
121+
* disallow uploading files with the following mimetypes
122+
* https://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types
123+
*/
124+
'unallowed_mimes' => ['php', 'java'],
125+
126+
/*
127+
* when file names gets cleand up
128+
*/
113129
'sanitized_text'=> 'sanitized',
114130

115-
// media manager root url
131+
/*
132+
* media manager root url
133+
*/
116134
'root_url'=> '/media',
117135

118-
// css farmework
136+
/*
137+
* css farmework
138+
*/
119139
'framework'=> env('MIX_MM_FRAMEWORK'),
120140
];
121141
```

src/Controllers/MediaController.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,19 @@ class MediaController extends Controller
1616
private $fileChars;
1717
private $folderChars;
1818
private $sanitizedText;
19+
private $unallowed_mimes;
1920
private $fw;
2021

2122
public function __construct()
2223
{
23-
$this->fileSystem = config('mediaManager.storage_disk');
24-
$this->storageDisk = Storage::disk($this->fileSystem);
25-
$this->ignoreFiles = config('mediaManager.ignore_files');
26-
$this->fileChars = config('mediaManager.allowed_fileNames_chars');
27-
$this->folderChars = config('mediaManager.allowed_folderNames_chars');
28-
$this->sanitizedText = config('mediaManager.sanitized_text');
29-
$this->fw = config('mediaManager.framework');
24+
$this->fileSystem = config('mediaManager.storage_disk');
25+
$this->storageDisk = Storage::disk($this->fileSystem);
26+
$this->ignoreFiles = config('mediaManager.ignore_files');
27+
$this->fileChars = config('mediaManager.allowed_fileNames_chars');
28+
$this->folderChars = config('mediaManager.allowed_folderNames_chars');
29+
$this->sanitizedText = config('mediaManager.sanitized_text');
30+
$this->unallowed_mimes = config('mediaManager.unallowed_mimes');
31+
$this->fw = config('mediaManager.framework');
3032
}
3133

3234
/**
@@ -57,8 +59,8 @@ public function upload(Request $request)
5759
$file_type = $one->getMimeType();
5860

5961
try {
60-
// stop if "php" or "jar"
61-
if (strpos($file_type, "php") || strpos($file_type, "java-")) {
62+
// check for mime type
63+
if (str_contains($file_type, $this->unallowed_mimes)) {
6264
throw new Exception(trans('MediaManager::messages.not_allowed_file_ext', ['attr'=>$file_type]));
6365
}
6466

src/config/mediaManager.php

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,46 @@
11
<?php
22

33
return [
4-
// ignore files pattern
4+
/*
5+
* ignore files pattern
6+
*/
57
'ignore_files' => '/^\..*/',
68

7-
// filesystem disk
9+
/*
10+
* filesystem disk
11+
*/
812
'storage_disk'=> 'public',
913

10-
// remove any file special chars except (. _ -)
14+
/*
15+
* remove any file special chars except (. _ -)
16+
*/
1117
'allowed_fileNames_chars'=> '.\_\-',
1218

13-
// remove any folder special chars except (_ -)
14-
// to add & nest folders in one go use '\/\_\-'
15-
'allowed_folderNames_chars'=> '\_\-',
19+
/*
20+
* remove any folder special chars except (_ -)
21+
*
22+
* to add & nest folders in one go use '\/\_\-'
23+
*/
24+
'allowed_folderNames_chars'=> '\/\_\-',
1625

17-
// when file names gets cleand up
26+
/*
27+
* disallow uploading files with the following mimetypes
28+
* https://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types
29+
*/
30+
'unallowed_mimes' => ['php', 'java'],
31+
32+
/*
33+
* when file names gets cleand up
34+
*/
1835
'sanitized_text'=> 'sanitized',
1936

20-
// media manager root url
37+
/*
38+
* media manager root url
39+
*/
2140
'root_url'=> '/media',
2241

23-
// css farmework
42+
/*
43+
* css farmework
44+
*/
2445
'framework'=> env('MIX_MM_FRAMEWORK'),
2546
];

0 commit comments

Comments
 (0)