@@ -130,7 +130,7 @@ Finally, you need to update the code of the controller that handles the form::
130130 class ProductController extends AbstractController
131131 {
132132 #[Route('/product/new', name: 'app_product_new')]
133- public function new(Request $request, SluggerInterface $slugger): Response
133+ public function new(Request $request, SluggerInterface $slugger, string $brochuresDirectory ): Response
134134 {
135135 $product = new Product();
136136 $form = $this->createForm(ProductType::class, $product);
@@ -150,10 +150,7 @@ Finally, you need to update the code of the controller that handles the form::
150150
151151 // Move the file to the directory where brochures are stored
152152 try {
153- $brochureFile->move(
154- $this->getParameter('brochures_directory'),
155- $newFilename
156- );
153+ $brochureFile->move($brochuresDirectory, $newFilename);
157154 } catch (FileException $e) {
158155 // ... handle exception if something happens during file upload
159156 }
@@ -219,7 +216,7 @@ You can use the following code to link to the PDF brochure of a product:
219216 // ...
220217
221218 $product->setBrochureFilename(
222- new File($this->getParameter('brochures_directory').'/' .$product->getBrochureFilename())
219+ new File($brochuresDirectory.DIRECTORY_SEPARATOR .$product->getBrochureFilename())
223220 );
224221
225222Creating an Uploader Service
0 commit comments