Skip to content
Browse files

handling upload error

  • Loading branch information...
1 parent dfcf4fd commit 87194f94d215543b999c172997b993dd20ba22e7 Robert Hill committed Jun 19, 2012
View
9 src/Blogger/GalleryBundle/Controller/GalleryController.php
@@ -42,8 +42,13 @@ public function newAction()
$i = $request->files->get($form->getName());
foreach($i["images"] as $im) {
- if($im->getSize()==0) {
- throw new FileException("There was an error uploading one or more files.\nThis may be because a file was larger than ".round(UploadedFile::getMaxFilesize()/1024/1024, 2)." MB.");
+ if($im->getError()===1) {
+
+ $mb = round(UploadedFile::getMaxFilesize()/1024/1024, 2);
+
+ return $this->render('BloggerGalleryBundle:Gallery:error.html.twig', array(
+ 'mb' => $mb
+ ));
}
$image = new Image();
$image->setFile(new UploadedFile($im->getPathName(),$im->getClientOriginalName()));
View
1 src/Blogger/GalleryBundle/Form/GalleryType.php
@@ -18,6 +18,7 @@ public function buildForm(FormBuilder $builder, array $options)
"attr" => array(
"accept" => "image/*",
"multiple" => "multiple",
+ "class" => "ererer",
)))
->add('tags');
}
View
4 src/Blogger/GalleryBundle/Resources/config/routing.yml
@@ -2,6 +2,10 @@ BloggerGalleryBundle_gallery_index:
pattern: /galleries
defaults: { _controller: BloggerGalleryBundle:Gallery:index }
+BloggerGalleryBundle_gallery_error:
+ pattern: /galleries/error
+ defaults: { _controller: BloggerGalleryBundle:Gallery:error, mb: 0 }
+
BloggerGalleryBundle_gallery_edit:
pattern: /galleries/{id}/{slug}/edit
defaults: { _controller: BloggerGalleryBundle:Gallery:edit }
View
9 src/Blogger/GalleryBundle/Resources/views/Gallery/error.html.twig
@@ -0,0 +1,9 @@
+
+{% extends 'BloggerGalleryBundle::layout.html.twig' %}
+
+{% block body %}
+ <h1>Upload Error</h1>
+ <p>There was an error uploading one or more files.</p>
+ <p>This may be because a file was larger than {{ mb }} MB.</p>
+
+{% endblock %}
View
BIN web/media/images/4fe09ef10afd9.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN web/media/images/4fe09ef10b2f9.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 87194f9

Please sign in to comment.
Something went wrong with that request. Please try again.