you have to enable file uploads. include enctype="multipart/form-data" in your form element.
Feb 28, 2016
14
Level 2
Upload csv file issue
I am having difficulty uploading csv file. I have set up the rules for csv file but it keeps saying the type is not correct. Here below is my view:
@extends('layouts.app') @section('content')
{{$title}}
@if(count($collections) > 0) @foreach($collections as $collection)Upload csv file
{{ Form::open(['method' => 'post', 'url' => 'projects/detail/'.$id, 'class' => 'form-horizontal', 'role' => 'form']) }} has('file') ? ' has-error' : '' }}"> {{ Form::file('file')}} @if ($errors->has('file')) {{ $errors->first('file') }} @endif <div class="form-group">
<div class="col-md-12">
<button type="submit" class="btn btn-primary">
Upload CSV
</button>
</div>
</div>
{{Form::close()}}
</div>
@endif
</div>
@stop
Here below is my controller.
public function storedetail(Request $request, $id){
$file = $request->input('file');
//$extension = File::extension($file);
$values = array(
'file' => $file
);
$rules = array(
'file' => 'required|mimes:csv'
);
$validator = Validator::make(
$values,
$rules
);
if ($validator->fails()){
return redirect()->back()->withErrors($validator->errors());
}
dd($file);
}
Thanks in advance.
Please or to participate in this conversation.