Skip to content

Update upload_file.rst for handling FileException #10382

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions controller/upload_file.rst
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,15 @@ Finally, you need to update the code of the controller that handles the form::

$fileName = $this->generateUniqueFileName().'.'.$file->guessExtension();

// moves the file to the directory where brochures are stored
$file->move(
$this->getParameter('brochures_directory'),
$fileName
);
// Move the file to the directory where brochures are stored
try {
$file->move(
$this->getParameter('brochures_directory'),
$fileName
);
} catch (FileException $e) {
// ... handle exception if something happens during file upload
}

// updates the 'brochure' property to store the PDF file name
// instead of its contents
Expand Down Expand Up @@ -234,7 +238,11 @@ logic to a separate service::
{
$fileName = md5(uniqid()).'.'.$file->guessExtension();

$file->move($this->getTargetDirectory(), $fileName);
try {
$file->move($this->getTargetDir(), $fileName);
} catch (FileException $e) {
// ... handle exception if something happens during file upload
}

return $fileName;
}
Expand Down