Skip to content

Commit d5aa913

Browse files
committed
Include better example using a parameter
1 parent afc6312 commit d5aa913

File tree

1 file changed

+1
-6
lines changed

1 file changed

+1
-6
lines changed

cookbook/controller/upload_file.rst

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,7 @@ Finally, you need to update the code of the controller that handles the form::
139139
$fileName = md5(uniqid()).'.'.$file->guessExtension();
140140

141141
// Move the file to the directory where brochures are stored
142-
$brochuresDir = $this->container->getParameter('kernel.root_dir').'/../web/uploads/brochures';
143-
$file->move($brochuresDir, $fileName);
142+
$file->move($this->container->getParameter('brochures_directory'), $fileName);
144143

145144
// Update the 'brochure' property to store the PDF file name
146145
// instead of its contents
@@ -175,10 +174,6 @@ There are some important things to consider in the code of the above controller:
175174
that information. That's why it's always better to generate a unique name and
176175
use the :method:`Symfony\\Component\\HttpFoundation\\File\\UploadedFile::guessExtension`
177176
method to let Symfony guess the right extension according to the file MIME type;
178-
#. The ``UploadedFile`` class also provides a :method:`Symfony\\Component\\HttpFoundation\\File\\UploadedFile::move`
179-
method to store the file in its intended directory. Defining this directory
180-
path as an application configuration option is considered a good practice that
181-
simplifies the code: ``$this->container->getParameter('brochures_dir')``.
182177

183178
You can use the following code to link to the PDF brochure of an product:
184179

0 commit comments

Comments
 (0)