В настоящее время я загружаю один файл изображения за один раз в базу данных mysql. Однако мне нужно загрузить 800 изображений, поэтому я хочу выбрать все изображения и загрузить их одним нажатием. Это мой PHP контроллерЗагрузите несколько файлов в форму PHP
/**
* @Route("/insert", name="satellite_images_create")
*/
public function insertAction(Request $request)
{
$satelliteImage=new satelliteImage;
$form=$this->createFormBuilder($satelliteImage)
->add('file')
->add('save',SubmitType::class,array('label'=>'Insert Image','attr'=>array('class'=>'btn btn-primary','style'=>'margin-bottom:15px')))
->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$em=$this->getDoctrine()->getManager();
$satelliteImage->upload();
$em->persist($satelliteImage);
$em->flush();
$this->addFlash(
'notice',
'Image inserted successfully'
);
return $this->redirectToRoute('satellite_images');
}
return $this->render('satelliteImages/insert.html.twig',array(
'form'=>$form->createView()));
}
SatelliteImage ЛИЦО имеет функцию для обработки время загрузки
public function upload()
{
// the file property can be empty if the field is not required
if (null === $this->getFile()) {
return;
}
$imgFile=$this->getFile();
$this->setImage(file_get_contents($imgFile));
$this->getFile()->move(
$this->getUploadRootDir(),
$this->getFile()->getClientOriginalName()
);
// set the path property to the filename where you've saved the file
$this->path = $this->getFile()->getClientOriginalName();
// clean up the file property as you won't need it anymore
$this->file = null;
}
А вот мой прутик файл
{% extends 'base.html.twig' %}
{% block body %}
<h2 class="page-header">Insert Image</h2>
{{ form_start(form) }}
{{ form_widget(form) }}
{{ form_end(form) }}
{% endblock %}
Как изменить форму и загрузить функцию, чтобы я мог выбрать все файлы изображений, которые будут загружены? Спасибо.
Ваш шаблон должен произвести необходимый HTML разрешить несколько загрузок файлов, т. е. – jeff
Это можно сделать. Но как я могу обработать его в контроллере? –