For upload multiple files you can construct your view using difrent instruction types: plain html, php, or Volt script template.
PHP example for 'form' tag
<?php echo $this->tag->form(array("controller/action", "name" => "actionForm", "method" => "post", "class" => "form-horizontal", 'enctype'=> "multipart/form-data" )) ?>
Volt example for 'form' tag
{{ form('controller/action', 'name': 'actionForm', 'method': 'post', 'class':'form-horizontal', 'enctype': 'multipart/form-data') }}
Or using plain html
<form target='controller/action' name='actionForm' method='post' class='form-horizontal' enctype='multipart/form-data' >
You must add the input tag for file upload and use the 'multiple' parameter like this
<input type="file" name="files[]" multiple>
<?php echo $this->tag->submitButton(array( "submit" , "class" => "btn btn-primary" ) ); ?>
</form>
in the controller you mus create a action to receibe the post methot with the files data.
This is an example to upload a pdf file or images.
First detect if ther are file uploads on the post, and then get a file data at a time to do some thing (copy to /some/rute/ or change name, etc.)
Then you can save the data to a database or do some thing whit the file.
...
public $extIMG = array(
'image/jpeg',
'image/png',
'image/bmp',
'application/pdf',
);
...
public function actionAction()
{
// are there files ?
if( $this->request->hasFiles() == true)
{
foreach( $this->request->getUploadedFiles() as $file)
{
// is it a valid extension?
if ( in_array($file->getType() , $this->extIMG) && $file->getError() == 0 )
{
$Name = preg_replace("/[^A-Za-z0-9.]/", '-', $file->getName() );
$FileName = "/some/path/to/pdfs" . $Name;
switch( strtolower($file->getExtension()) ){
case "pdf":
// move file to needed path";
if(!$file->moveTo($FileName))
{
// something goes worong
$this->flash->error("Ocurrio un error al subir el documento.");
return $this->dispatcher->forward(
array(
"controller" => "incident`",
"action" => "new",
));
}
// all fine the file has been moved
break;
}
// do some thing
}
}
}
}
Get fun whit the code, good luk.