Reputation: 51
I would like to display the images that I uploaded in a multiple input file; the input file is located in a form that targets my display page:
<form method="POST" action="{{ 'etape_4'|page }}" accept-charset="UTF8" enctype="multipart/form-data">
<input type="hidden" name="_handler" value="onTest">
{{form_token()}}
{{form_sessionkey()}}
Upload photo: <input name="photo[]" type="file" id="photo" multiple="multiple" />
<div class=" col-sm-offset-3 col-sm-9">
<button type="submit" class="btn btn-default">Suivant</button>
</div>
</form>
and here is the display page:
title = "etape_4"
url = "/etape_4"
is_hidden = 0
==
<?php
function onStart()
{
$this['file'] = new \System\Models\File;
$this['file']->fromFile(Input::file('photo'));
}
?>
==
<ul>
{%for image in file%}
<li>
{{image.path}}
<img src="{{image.path}}">
{%endfor%}
</li>
</ul>
when i choose the images and submit the page i get this error:
is_file() expects parameter 1 to be a valid path, array given
so what is the solution ? please help me !
Upvotes: 0
Views: 148
Reputation: 9693
It seems you are uploading multiple files and treating them as single file Object
lets correct
onStart
method to support multiple files
function onStart()
{
$files = [];
$multipleFiles = Input::file('photo');
foreach($multipleFiles as $singleFile) {
$fileModel = new \System\Models\File;
$fileModel->fromFile($singleFile);
$files[] = $fileModel;
}
$this['file'] = $files;
}
Just replace your
onStart
code with this one it should work.
If any doubts please comment.
Upvotes: 1