Laravel多文件上传5.6

时间:2018-03-28 01:21:27

标签: laravel

问题是我的存储文件目录根本不起作用。如果我可以保存文件夹方向,我可以显示文件夹的所有文件。

create.blade.php

{!! Form::open(['method' => 'POST', 'route' => ['materials.store'], 'files' => true]) !!}
<div class="form-group">
    {!! Form::label('name', 'Файлаа энд хуулна уу') !!}
    {!! Form::file('attachments[]', ['roles' => 'form', 'multiple' => 'multiple']) !!}
    {!! Form::token() !!}
</div>
    {!! Form::submit('Submit', ['class' => 'btn btn-success'])  !!}
<a href="{{ url()->previous() }}" class="btn btn-default">Back</a>
{!! Form::close() !!}

materialscontroller @创建

dd($request,$files);

配置/ app.php

'fileDestinationPath' => 'uploads',
'allowedFileTypes' => 'jpg,jpeg,bmp,png,pdf',
'maxFileSize' => 1000000*2,

结果

"_token" => "9Oxhj6WrzJGAl3Dw8LV9cw6QvW7nT5PhittIiJL8"
"title" => "China"
"description" => "Deleniti nobis earum voluptatem facere quis eiusmod occaecat nostrum commodo soluta sit beatae nesciunt quia quasi"

它的show.blade.php就是我如何打印

<h1><b>Хэлтэс : </b> {{ $material->title }}</h1><hr> 
<p class="lead"><b>Агуулга : </b>{{ $material->description }}</p><hr>
@foreach($files as $file)
<a href="http://localhost/QuizApp/resources/app/{{ $file }}">Файл татах</br></a>
@endforeach

MaterialsController

foreach ($files as $file) {
$fileName = $file->getClientOriginalName();
$uploaded = Storage::put($destinationPath.$fileName.'.'.$file->getClientOriginalExtension(),file_get_contents($file->getRealPath()));
}
    if($uploaded){
        Material::create([
            'description' => $request->input('description'),
            'title' => $request->input('title'),
            'filename' => $date,
        ]);

1 个答案:

答案 0 :(得分:1)

检查Model检查migrations,然后检查destinationPath。我认为你的代码很好。你的Model效果不佳。我想