多个文件上传时,调用成员函数getClientOriginalName()为null

时间:2018-12-12 08:53:11

标签: php laravel-4.2

我想将多个文件上载到目录并对表进行惰性处理,但是出现以下错误:

Call to a member function getClientOriginalName() on null

下面是我的代码:

控制器

$editLogistic = LogisticTransaction::find($id);
$batchid = $editLogistic->id;

if(Input::file('attachment')) {
    foreach(Input::file('attachment') as $image) {
        $filename =  date("Ymdhis")."-".uniqid();
        $filename = $filename.".".$image->getClientOriginalName();
        $path=public_path('logistic/images');
        $x= $image->move($path,  $filename);

        DB::table('logistic_batch_attachment')->insertGetId(array(
            'batch_id'     =>  $editLogistic->id,
            'filename'     =>  $filename,
            'path_to_file' =>  $path,
        ));
    }
}

视图

{{
    Form::open(array(
        'url'=>'jlogistic/edit/'.$logistic->id,
        'class' => 'form-horizontal',
        'files' => true,
        'enctype'=>'multipart/form-data','method'=>'post'
    ))
}}

<div class="form-group increment">
    <label  class="col-lg-2 control-label">Attachment</label>
        <div class="col-lg-3">
            <input type="file" name="attachment[]" class="form-control">
        </div>
        <div class="input-group-btn"> 
            <button class="btn btn-success" type="button">
                <i class="glyphicon glyphicon-plus"></i>Add
            </button>
        </div>
</div>

我收到此错误,但是文件正在移动到文件夹并插入数据库中:

  

在null上调用成员函数getClientOriginalName()

0 个答案:

没有答案