Laravel 5.3 多文件上传
                            本文介绍了Laravel 5.3 多文件上传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
                        
                        问题描述
如何在 Laravel 5.3 中上传多个文件.如果我尝试使用 1 张图片,它可以工作,但未上传多张图片.
How can I upload multiple files in Laravel 5.3.
If I try it with 1 image it works but multiple images are not uploaded.
这是我的代码:
if($request->hasFile('attachment')) {
    foreach($request->allFiles('attachments') as $file) {
        $file->store('users/' . $user->id . '/messages');
    }
}
推荐答案
现在是这样的:
$files = $request->file('attachment');
if($request->hasFile('attachment'))
{
    foreach ($files as $file) {
        $file->store('users/' . $this->user->id . '/messages');
    }
}
我必须在 name 属性的值后附加 [],所以:
I had to append [] after the value of the name attribute, so:
<input type="file" name="attachment[]" multiple>
                        这篇关于Laravel 5.3 多文件上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
