私は現在、一度に1つの画像ファイルを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 ENTITYアップロード
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 %}
です私はアップロードするすべての画像ファイルを選択することができるように機能をアップロード?ありがとう。
の複製であります複数のファイルをアップロードできるようにする – jeff
これを行うことができます。しかし、コントローラでどのように扱うことができますか? –