Skip to content

Commit

Permalink
- Added sanitizing user file names
Browse files Browse the repository at this point in the history
  • Loading branch information
dash8x committed Mar 24, 2024
1 parent 4926170 commit ff1f070
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Media/UpdateMedia.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ public function updateSingleMedia($collection, Request $request, $key = '')
//remove the existing file
$this->clearMediaCollection($collection);

$original_file_name = app(config('media-library.file_namer'))->originalFileName($file->getClientOriginalName());

// add the new file
return $this->addMedia($file)
//->usingFileName(Str::slug(Str::random(8)).'.'.$file->guessExtension())
->usingFileName(Str::slug($original_file_name . '-' . Str::random(4)).'.'.$file->guessExtension())
->toMediaCollection($collection);
} elseif ($request->exists($key)) {
//remove file if the parameter is empty
Expand Down

0 comments on commit ff1f070

Please sign in to comment.