@@ -122,7 +122,7 @@ Finally, you need to update the code of the controller that handles the form::
122
122
if ($form->isValid()) {
123
123
// $file stores the uploaded PDF file
124
124
/** @var Symfony\Component\HttpFoundation\File\UploadedFile $file */
125
- $file = $product->getBrochure()
125
+ $file = $product->getBrochure();
126
126
127
127
// Generate a unique name for the file before saving it
128
128
$fileName = md5(uniqid()).'.'.$file->guessExtension();
@@ -135,13 +135,13 @@ Finally, you need to update the code of the controller that handles the form::
135
135
// instead of its contents
136
136
$product->setBrochure($filename);
137
137
138
- // persist the $product variable or any other work...
138
+ // ... persist the $product variable or any other work
139
139
140
140
return $this->redirect($this->generateUrl('app_product_list'));
141
141
}
142
142
143
143
return $this->render('product/new.html.twig', array(
144
- 'form' => $form->createView()
144
+ 'form' => $form->createView(),
145
145
));
146
146
}
147
147
}
@@ -150,10 +150,10 @@ There are some important things to consider in the code of the above controller:
150
150
151
151
#. When the form is uploaded, the ``brochure `` property contains the whole PDF
152
152
file contents. Since this property stores just the file name, you must set
153
- its new value before persisting the changes of the entity.
153
+ its new value before persisting the changes of the entity;
154
154
#. In Symfony applications, uploaded files are objects of the
155
155
:class: `Symfony\\ Component\\ HttpFoundation\\ File\\ UploadedFile ` class, which
156
- provides methods for the most common operations when dealing with uploaded files.
156
+ provides methods for the most common operations when dealing with uploaded files;
157
157
#. A well-known security best practice is to never trust the input provided by
158
158
users. This also applies to the files uploaded by your visitors. The ``Uploaded ``
159
159
class provides methods to get the original file extension
@@ -163,7 +163,7 @@ There are some important things to consider in the code of the above controller:
163
163
However, they are considered *not safe * because a malicious user could tamper
164
164
that information. That's why it's always better to generate a unique name and
165
165
use the :method: `Symfony\\ Component\\ HttpFoundation\\ File\\ UploadedFile::guessExtension `
166
- method to let Symfony guess the right extension according to the file MIME type.
166
+ method to let Symfony guess the right extension according to the file MIME type;
167
167
#. The ``UploadedFile `` class also provides a :method: `Symfony\\ Component\\ HttpFoundation\\ File\\ UploadedFile::move `
168
168
method to store the file in its intended directory. Defining this directory
169
169
path as an application configuration option is considered a good practice that
0 commit comments