Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit eb637f0

Browse filesBrowse 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
Copy full SHA for eb637f0

File tree

1 file changed

+11
-2
lines changed
Filter options

1 file changed

+11
-2
lines changed

‎controller/upload_file.rst

Copy file name to clipboardExpand all lines: controller/upload_file.rst
+11-2Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.