From 528a54619f835766dc8930ded1b387fe42533b5d Mon Sep 17 00:00:00 2001 From: Yoan Arnaudov Date: Tue, 8 Aug 2023 12:11:37 +0300 Subject: [PATCH] Fix File Upload Example --- controller/upload_file.rst | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/controller/upload_file.rst b/controller/upload_file.rst index 886c772d98a..2d6ad260491 100644 --- a/controller/upload_file.rst +++ b/controller/upload_file.rst @@ -222,9 +222,13 @@ You can use the following code to link to the PDF brochure of a product: use Symfony\Component\HttpFoundation\File\File; // ... - $product->setBrochureFilename( - new File($this->getParameter('brochures_directory').'/'.$product->getBrochureFilename()) - ); + if (!$form->isSubmitted() && $product->getBrochureFilename()) { + $form->setData(['brochure' => new File($this->getParameter('brochures_directory').'/'.$product->getBrochureFilename())]); + } + + if ($form->isSubmitted() && $form->isValid()) { + // ... + } Creating an Uploader Service ----------------------------