Skip to content

Commit eb637f0

Browse files
committed
minor #9179 uploading example: explaining the need for md5 (MacDada, javiereguiluz)
This PR was submitted for the 4.0 branch but it was merged into the 2.7 branch instead (closes #9179). Discussion ---------- uploading example: explaining the need for md5 Plus extracted function with a name that makes the comment unnecessary. Commits ------- 9321577 Reword a code comment 6185887 uploading example: explaining the need for md5
2 parents 48cd7f8 + 9321577 commit eb637f0

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

controller/upload_file.rst

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,7 @@ Finally, you need to update the code of the controller that handles the form::
136136
/** @var Symfony\Component\HttpFoundation\File\UploadedFile $file */
137137
$file = $product->getBrochure();
138138

139-
// Generate a unique name for the file before saving it
140-
$fileName = md5(uniqid()).'.'.$file->guessExtension();
139+
$fileName = $this->generateUniqueFileName().'.'.$file->guessExtension();
141140

142141
// Move the file to the directory where brochures are stored
143142
$file->move(
@@ -158,6 +157,16 @@ Finally, you need to update the code of the controller that handles the form::
158157
'form' => $form->createView(),
159158
));
160159
}
160+
161+
/**
162+
* @return string
163+
*/
164+
private function generateUniqueFileName()
165+
{
166+
// md5() reduces the similarity of the file names generated by
167+
// uniqid(), which is based on timestamps
168+
return md5(uniqid());
169+
}
161170
}
162171

163172
Now, create the ``brochures_directory`` parameter that was used in the

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy