From 15ca0fce55cc800551d8fd299cdd975f843bb0a0 Mon Sep 17 00:00:00 2001 From: Luca Suriano Date: Sun, 23 Sep 2018 11:46:14 +0200 Subject: [PATCH 1/2] FileException handled FileException handled in examples. This is for bc with 2.8. We need to discuss how to handle specific file exceptions ;) --- controller/upload_file.rst | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/controller/upload_file.rst b/controller/upload_file.rst index 8ff80e7debd..27cc31a1e22 100644 --- a/controller/upload_file.rst +++ b/controller/upload_file.rst @@ -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 is something happens during file upload + } // updates the 'brochure' property to store the PDF file name // instead of its contents @@ -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 is something happens during file upload + } return $fileName; } From af42a473b64962d0afa3177dea7fc3c75d244beb Mon Sep 17 00:00:00 2001 From: Luca Suriano Date: Wed, 26 Sep 2018 12:43:13 +0200 Subject: [PATCH 2/2] Update upload_file.rst Typo fixed :) --- controller/upload_file.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/controller/upload_file.rst b/controller/upload_file.rst index 27cc31a1e22..5feeeaa9202 100644 --- a/controller/upload_file.rst +++ b/controller/upload_file.rst @@ -130,7 +130,7 @@ Finally, you need to update the code of the controller that handles the form:: $fileName ); } catch (FileException $e) { - // ... handle exception is something happens during file upload + // ... handle exception if something happens during file upload } // updates the 'brochure' property to store the PDF file name @@ -241,7 +241,7 @@ logic to a separate service:: try { $file->move($this->getTargetDir(), $fileName); } catch (FileException $e) { - // ... handle exception is something happens during file upload + // ... handle exception if something happens during file upload } return $fileName;