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:"
Mohan Rajan :
As per the given documentation. Try this.\n\nWhen Via Facade , Its through\n\nRequest::file('filename');\n\n\nWhen via controller , change your postupload function like this.\n\npublic function postUpload(Request $request)\n{\n$file = $request->file('filename');\necho dd($file);\n}\n\n\nNot 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.",
2015-12-09T12:01:33