Ruka Xing
Ruka Xing

Reputation: 642

Laravel Multiple file upload 5.6

Problem is my storing file directory is not working at all. If i could save Folders Direction i can show all files of folder.

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@create

dd($request,$files);

config/app.php

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

Result is

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

Its show.blade.php thats how i print

<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,
        ]);

Upvotes: 2

Views: 2593

Answers (1)

Elliot
Elliot

Reputation: 580

Check your Model check your migrations then check destinationPath. I think your code is fine. Your Model is not working as good. I guess

Upvotes: 1

Related Questions