php - Multiple Image Upload only uploading one image in Symfony 3? -
i'm building function upload multiple images our website, , far have upload form:
<?php namespace tyson\adminbundle\form; use doctrine\orm\entityrepository; use symfony\component\form\abstracttype; use symfony\component\form\formbuilderinterface; use symfony\component\form\extension\core\type\submittype; use symfony\component\form\extension\core\type\filetype; use symfony\component\form\extension\core\type\integertype; class iutype extends abstracttype { public function buildform(formbuilderinterface $builder, array $options) { $builder->add('id', integertype::class); $builder->add('image', filetype::class, array( 'attr' => array( 'multiple' => 'true', 'data_class' => null ) )); } public function getname() { return 'iu'; } }
this displayed on twig file this:
<div class="tabs-panel" id="panel3v"> {{ form_start(iu,{action:path('admin_upload-images')}) }} <div class="row"> <div class="small-3 medium-3 large-3 columns field-label"> <label>image id</label> </div> <div class="small-9 medium-9 large-9 columns"> {{ form_widget(iu.id) }} {{ form_errors(iu.id) }} </div> </div> <div class="row"> <div class="small-3 medium-3 large-3 columns field-label"> <label>image upload</label> </div> <div class="small-9 medium-9 large-9 columns"> {{ form_widget(iu.image) }} {{ form_errors(iu.image) }} </div> </div> <div class="row"> <div class="small-6 medium-6 large-6 columns"> <button type="submit" class="button" id="savebtn">save changes</button> </div> </div> {{ form_end(iu) }} </div>
when submitted, during testing, i'm outputting handed controller form. output:
[files] => symfony\component\httpfoundation\filebag object ( [parameters:protected] => array ( [iu] => array ( [image] => symfony\component\httpfoundation\file\uploadedfile object ( [test:symfony\component\httpfoundation\file\uploadedfile:private] => [originalname:symfony\component\httpfoundation\file\uploadedfile:private] => cny8drqxyaaoaaw.jpg [mimetype:symfony\component\httpfoundation\file\uploadedfile:private] => image/jpeg [size:symfony\component\httpfoundation\file\uploadedfile:private] => 35164 [error:symfony\component\httpfoundation\file\uploadedfile:private] => 0 [pathname:splfileinfo:private] => /tmp/phpibzuvw [filename:splfileinfo:private] => phpibzuvw ) ) )
i select 1 image, or 100 images, , still form passing me 1 image before controller else.
for reference, code controller far:
<?php namespace tyson\adminbundle\controller; use symfony\bundle\frameworkbundle\controller\controller; use symfony\component\security\core\securitycontext; use symfony\component\security\core\user\userinterface; use tyson\corebundle\entity\images; use symfony\component\httpfoundation\request; use symfony\component\httpfoundation\cookie; use symfony\component\httpfoundation\session\session; use symfony\component\form\form; use symfony\component\httpfoundation\response; use symfony\component\httpfoundation\redirectresponse; use symfony\component\httpfoundation\jsonresponse; use symfony\component\filesystem\filesystem; use symfony\component\filesystem\exception\ioexceptioninterface; use symfony\component\httpfoundation\file\uploadedfile; class uploadcontroller extends controller { public function uploadimagesaction(request $request) { $fs = new filesystem(); $dm = $this->getdoctrine()->getmanager(); $dir = '/var/www/html/tyson/web/uploads/images/'; $request = $this->get('request_stack')->getcurrentrequest(); $formdet = $request->request->get('iu'); $imgid = $formdet['id']; $folderpath = '/var/www/html/tyson/web/uploads/images/'.$imgid; $imgdirectory = '/var/www/html/tyson/web/uploads/images/'.$imgid.'/'; $foldercheck = $fs->exists($folderpath); print_r($request); die(); } }
i'd imagine file
output should contain more 1 image controller (as form submitted once, not repeatedly), doing wrong happen?
same problem form me
$builder->add('files', filetype::class, array('required' => false, 'mapped' => false, 'attr' => array( 'multiple' => true ), ));
only 1 file submitted. no solutions me now, add [] javascript upload name.
Comments
Post a Comment