Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.30 KB | None | 0 0
  1. class UploadedData {
  2.    
  3.     /**
  4.      * @Assert\File(maxSize="6000000")
  5.      */
  6.     public $file;
  7.    
  8.     /**
  9.      * @Assert\NotBlank
  10.      */
  11.     public $name;
  12. }
  13.  
  14.   public function addAction(){
  15.  
  16.     $uploadedData = new UploadedData();
  17.      
  18.     $formUpload = $this->createFormBuilder($uploadedData)
  19.         ->add('file')
  20.         ->add('name')
  21.         ->getForm();
  22.    
  23.     $debug = '';
  24.     $photos = array();
  25.  
  26.     if ($this->get('request')->getMethod() === 'POST'){
  27.  
  28.       $formUpload->bindRequest($this->get('request'));
  29.  
  30.       if ($this->get('request')->get('submit-photo'))
  31.       {
  32.         for ($i = 0; $i < 3; $i++) {
  33.             $photo = $this->get('request')->get("photo-".$i);
  34.             if (isset($photo)){
  35.                 array_push($photos,$photo);    
  36.             }
  37.         }
  38.            
  39.         if($formUpload->isValid())
  40.         {      
  41.             $debug = $debug.' Upload OK';
  42.         }else{
  43.             $debug = $debug.' Invalid Upload';
  44.         }
  45.       }
  46.     }
  47.      
  48.     return $this->container->get('templating')->renderResponse('LCShopBundle:Item:add.html.twig',
  49.     array(
  50.           'formUpload' => $formUpload->createView(),
  51.           'photos' => $photos,  
  52.           'debug' => $debug)
  53.     );
  54.  
  55.   }
  56.  
  57. {{ form_widget(formUpload.file) }}<input type="submit" name="submit-photo" value="Load">
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement