Skip to content

Commit ae2576f

Browse files
committed
Minor code tweaks
1 parent 2019e6d commit ae2576f

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

controller/upload_file.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ Finally, you need to update the code of the controller that handles the form::
127127
$brochureFile = $form['brochure']->getData();
128128
$originalFilename = pathinfo($brochureFile->getClientOriginalName(), PATHINFO_FILENAME);
129129
// this is needed to safely include the file name as part of the URL
130-
$originalFilename = transliterator_transliterate('Any-Latin; Latin-ASCII; Lower()', $originalFilename);
131-
$newFilename = $originalFilename.'-'.uniqid().'.'.$brochureFile->guessExtension();
130+
$safeFilename = transliterator_transliterate('Any-Latin; Latin-ASCII; [^A-Za-z0-9_] remove; Lower()', $originalFilename);
131+
$newFilename = $safeFilename.'-'.uniqid().'.'.$brochureFile->guessExtension();
132132

133133
// Move the file to the directory where brochures are stored
134134
try {
@@ -227,8 +227,8 @@ logic to a separate service::
227227
public function upload(UploadedFile $file)
228228
{
229229
$originalFilename = pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME);
230-
$originalFilename = transliterator_transliterate('Any-Latin; Latin-ASCII; Lower()', $originalFilename);
231-
$fileName = $originalFilename.'-'.uniqid().'.'.$file->guessExtension();
230+
$safeFilename = transliterator_transliterate('Any-Latin; Latin-ASCII; [^A-Za-z0-9_] remove; Lower()', $originalFilename);
231+
$fileName = $safeFilename.'-'.uniqid().'.'.$file->guessExtension();
232232

233233
try {
234234
$file->move($this->getTargetDirectory(), $fileName);

0 commit comments

Comments
 (0)