diff --git a/controller/upload_file.rst b/controller/upload_file.rst index dda7491124d..2c6e7434b54 100644 --- a/controller/upload_file.rst +++ b/controller/upload_file.rst @@ -132,8 +132,7 @@ Finally, you need to update the code of the controller that handles the form:: /** @var Symfony\Component\HttpFoundation\File\UploadedFile $file */ $file = $product->getBrochure(); - // Generate a unique name for the file before saving it - $fileName = md5(uniqid()).'.'.$file->guessExtension(); + $fileName = $this->generateUniqueFileName().'.'.$file->guessExtension(); // Move the file to the directory where brochures are stored $file->move( @@ -154,6 +153,16 @@ Finally, you need to update the code of the controller that handles the form:: 'form' => $form->createView(), )); } + + /** + * @return string + */ + private function generateUniqueFileName() + { + // md5() reduces the similarity of the file names generated by + // uniqid(), which is based on timestamps + return md5(uniqid()); + } } Now, create the ``brochures_directory`` parameter that was used in the