Skip to content

Commit fd06f6b

Browse files
committed
fix(media): Allowed ext should be an array
Also moves config lookup outside of loop to avoid unnecessary rechecks
1 parent 7f300b4 commit fd06f6b

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

app/Modules/Media/Config/config.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,15 @@
1212
|--------------------------------------------------------------------------
1313
| Specify all the allowed file extensions a user can upload on the server
1414
|--------------------------------------------------------------------------
15+
| List of lowercase file extensions. Example:
16+
| [
17+
| 'bmp','csv','doc','docx','epg','eps','gif','ico','jpg','jpeg','jpe',
18+
| 'key','keynote','mp4','mp3','m4a','m4v','odg','odp','ods','odt','pdf',
19+
| 'png','ppt','pptx','svg','txt','xcf','xls','xlsx','webp','avif','zip'
20+
| ]
21+
| Leave empty to allow any file type.
1522
*/
16-
'allowed-extensions' => 'bmp,csv,doc,docx,epg,eps,gif,ico,jpg,jpeg,key,keynote,mp4,mp3,m4a,m4v,odg,odp,ods,odt,pdf,png,ppt,pptx,swf,txt,xcf,xls,xlsx,svg',
23+
'allowed-extensions' => [],
1724

1825
/*
1926
|--------------------------------------------------------------------------

app/Modules/Media/Http/Controllers/Api/MediaController.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,12 @@ public function upload(Request $request): JsonResponse
239239
}
240240

241241
$fileNotUploaded = false;
242+
$maxSize = config('module.media.max-file-size', 0);
243+
$allowedTypes = config('module.media.allowed-extensions', []);
244+
if (is_string($allowedTypes))
245+
{
246+
$allowedTypes = explode(',', $allowedTypes);
247+
}
242248

243249
foreach ($files as $file)
244250
{
@@ -250,8 +256,6 @@ public function upload(Request $request): JsonResponse
250256
}
251257

252258
// Check file size
253-
$maxSize = config('module.media.max-file-size', 0);
254-
255259
if (($maxSize && $file->getSize() / 1024 > $maxSize)
256260
|| $file->getSize() / 1024 > $file->getMaxFilesize())
257261
{
@@ -269,8 +273,6 @@ public function upload(Request $request): JsonResponse
269273
}*/
270274

271275
// Check allowed file type
272-
$allowedTypes = config('module.media.allowed-extensions', []);
273-
274276
if (!empty($allowedTypes)
275277
&& !in_array(
276278
$file->getClientOriginalExtension(),

0 commit comments

Comments
 (0)