I can't upload excel file in Laravel 5.
I have following error:
TokenMismatchException in VerifyCsrfToken.php line
View
<form action="{{url('raports/upload')}}" method="post" enctype="multipart/form-data">
<input name="_token" type="hidden" value="{!! csrf_token() !!}" />
<input type="file" name="plik" >
<input type="submit" class="btn btn-primary" value="Upload File"/>
</form>
Controller
public function postUpload()
{
$validator = Validator::make(Request::all() , ['plik' => 'required']);
if ($validator->fails()) {
return redirect('raports/upload')
->withErrors($validator)
->withInput();
}
else
{
$file = Request::file('plik');
dd($file->getClientOriginalName());
}
}
When I try upload txt file everything is OK, but not with excel files.
Any ideas?
Maybe it is a problem from nginx:
2015/12/09 19:30:32 [error] 24145#0: *1233663 FastCGI sent in stderr: "PHP message: PHP Warning: REQUEST_BODY_FILE: open('/var/lib/nginx/body/0000007523') failed: No such file or directory (2) in Unknown on line 0" while reading response header from upstream, client: 91.226.23.2, server: domain.com, request: "POST /raports/upload HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:"
As per the given documentation. Try this.
When Via Facade , Its through
Request::file('filename');
When via controller , change your postupload function like this.
public function postUpload(Request $request)
{
$file = $request->file('filename');
echo dd($file);
}
Not Sure whether this is the problem , If it doesnt work then too , then you can go to your Directory/public to check whether it has been uploaded into the public folder . If it does , can you show me the error thrown . If not , Then the problem is with the request.
This error occurs when you try to submit a file that's beyond the **post_max_size**
set in your php.ini in your server.
Increase the **post_max_size**
size to a value like 100000 and try it.