Answer the question
In order to leave comments, you need to log in
Laravel 5.4. How to upload files to the site?
Hello!
How do you implement file uploads, and why does the script not see the files that I want to upload to the site?
$files = Input::file('images');
dd($files); // возращает null
<form action="carts" method="post">
{{ csrf_field() }}
<div class="form-group">
<label for="name" class="col-md-4 control-label">ФИО клиента</label>
<div class="col-md-6">
<input name="name" type="text" id="name" class="form-control" required autofocus>
</div>
</div>
<div class="form-group">
<label for="url" class="col-md-4 control-label">Url страницы</label>
<div class="col-md-6">
<span>{{ config('app.url') }}/{{$random}}</span>
<input id="url" type="hidden" class="form-control" name="url" value="{{$random}}" required>
</div>
</div>
<div class="form-group">
<label for="image" class="col-md-4 control-label">Фотографии</label>
<div class="col-md-6">
<input type="file" name="images" multiple>
</div>
</div>
<div class="form-group">
<div class="col-md-8 col-md-offset-4">
<button type="submit" class="btn btn-primary">
Создать
</button>
</div>
</div>
</form>
public function store(Request $request)
{
PersonalCart::create([
'name_user' => $request->name,
'url_cart' => $request->url
]);
if (Input::hasFile('images'))
{
$files = Input::file('images');
foreach($files as $file) {
$destinationPath = public_path() .'/uploads/';
$filename = $file->getClientOriginalName();
$file->move($destinationPath, $filename);
}
}
}
Route::get('/', '[email protected]');
Route::post('/carts', '[email protected]');
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question