dou70260 2018-07-24 22:13
浏览 303
已采纳

'multipart / form-data'无效

I'm using Laravel and trying to build a gallery, i'm testing the upload of a file but i when i attach a file and click submit i can't get a positive outcome using the test set up. The code is below

GalleryController

// Store Gallery
    public function store(Request $request){
            // Get Request Input
        $name = $request->input ('name');        
        $description = $request->input ('description', '');
        $cover_image = $request->input ('cover_image');
        $owner_id = 1;

        // Check Image Upload
        if($cover_image){
die ('YES');
        } else {
die ('NO');
        }
    }

The form is set up as follows

{!! Form::open(array('action' => 'GalleryController@store', 'enctype' => 'multipart/form-data')) !!}
              {!! Form::label ('name', 'Name') !!}
              {!! Form::text ('name', $value = null, $attributes = ['placeholder' => 'Gallery Name', 'name' => 'name']) !!}

            {!! Form::label ('description', 'Description') !!}
              {!! Form::text ('name', $value = null, $attributes = ['placeholder' => 'Gallery Description', 'name' => 'Description']) !!}

            {!! Form::label ('cover_image', 'Cover Image') !!}
            {!! Form::file('cover_image') !!}

            {!! Form::submit ('Submit', $attributes = ['class' => 'button']) !!}
            {!! Form::close() !!}

Any help is appreciated Thanks

  • 写回答

2条回答 默认 最新

  • dongtou2016 2018-07-24 23:23
    关注

    Your form looks correct, it is likely your controller where you are retrieving the uploaded file.

    As per the docs, to retrieve an uploaded file you should use $request->file():

     $request->file('cover_image');
    

    That link to the docs above also goes on to explain how you can check the file properly and store the file.

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

报告相同问题?

悬赏问题

  • ¥15 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥15 DruidDataSource一直closing
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据