dou426098 2015-12-09 11:19
浏览 426
已采纳

在Laravel 5中上传excel文件

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:"

  • 写回答

2条回答 默认 最新

  • dongxin5429 2015-12-09 12:01
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏