如何在 octobercms 中显示来自多个输入文件的图像
how to display images from an multiple input file in octobercms
我想在多输入文件中显示我上传的图片;
输入文件位于以我的显示页面为目标的表单中:
<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>
这是显示页面:
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>
当我选择图像并提交页面时,出现此错误:
is_file() expects parameter 1 to be a valid path, array given
那么解决方案是什么?
请帮助我!
看来你是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.
如有疑问请评论。
我想在多输入文件中显示我上传的图片; 输入文件位于以我的显示页面为目标的表单中:
<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>
这是显示页面:
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>
当我选择图像并提交页面时,出现此错误:
is_file() expects parameter 1 to be a valid path, array given
那么解决方案是什么? 请帮助我!
看来你是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.
如有疑问请评论。