如何在octobercms上传多个图像?

问题描述 投票:0回答:1

我已经看过如何在octobercms上传多个图像或文件,但它还没有为我工作。

我试过将[]添加到名称属性,如name ='images []',但它只上传最后一张图片

我的代码目前在PostForm.php

$advert->allimage = Input::file('allimage');

default.htm

<div >
  <input type="file" name="allimage[]" accept="image/*" multiple="multiple" >
  <label  >Choose file</label>
</div>

我甚至将enctype="multipart/form-data"添加到表单中但没有运气

php laravel octobercms
1个回答
0
投票

试试这段代码:

foreach (Input::file('allimage') as $file) {
    $advert->allimage()->create(['data' => $file]);
}

但请确保您在广告模型中定义了attachMany关系:

public $attachMany = [
    'allimage' => 'System\Models\File'
];

查看更多信息here

或者只是尝试保存您的模型:

$advert->allimage = Input::file('allimage');
$advert->save();
© www.soinside.com 2019 - 2024. All rights reserved.