Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

Commit

Permalink
handling upload error
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Hill committed Jun 19, 2012
1 parent dfcf4fd commit 87194f9
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/Blogger/GalleryBundle/Controller/GalleryController.php
Expand Up @@ -42,8 +42,13 @@ public function newAction()
$i = $request->files->get($form->getName()); $i = $request->files->get($form->getName());


foreach($i["images"] as $im) { foreach($i["images"] as $im) {
if($im->getSize()==0) { if($im->getError()===1) {
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.");
$mb = round(UploadedFile::getMaxFilesize()/1024/1024, 2);

return $this->render('BloggerGalleryBundle:Gallery:error.html.twig', array(
'mb' => $mb
));
} }
$image = new Image(); $image = new Image();
$image->setFile(new UploadedFile($im->getPathName(),$im->getClientOriginalName())); $image->setFile(new UploadedFile($im->getPathName(),$im->getClientOriginalName()));
Expand Down
1 change: 1 addition & 0 deletions src/Blogger/GalleryBundle/Form/GalleryType.php
Expand Up @@ -18,6 +18,7 @@ public function buildForm(FormBuilder $builder, array $options)
"attr" => array( "attr" => array(
"accept" => "image/*", "accept" => "image/*",
"multiple" => "multiple", "multiple" => "multiple",
"class" => "ererer",
))) )))
->add('tags'); ->add('tags');
} }
Expand Down
4 changes: 4 additions & 0 deletions src/Blogger/GalleryBundle/Resources/config/routing.yml
Expand Up @@ -2,6 +2,10 @@ BloggerGalleryBundle_gallery_index:
pattern: /galleries pattern: /galleries
defaults: { _controller: BloggerGalleryBundle:Gallery:index } defaults: { _controller: BloggerGalleryBundle:Gallery:index }


BloggerGalleryBundle_gallery_error:
pattern: /galleries/error
defaults: { _controller: BloggerGalleryBundle:Gallery:error, mb: 0 }

BloggerGalleryBundle_gallery_edit: BloggerGalleryBundle_gallery_edit:
pattern: /galleries/{id}/{slug}/edit pattern: /galleries/{id}/{slug}/edit
defaults: { _controller: BloggerGalleryBundle:Gallery:edit } defaults: { _controller: BloggerGalleryBundle:Gallery:edit }
Expand Down
@@ -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 %}
Binary file added 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.
Binary file added 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.