【问题标题】:Laravel upload image through Cloudder and Cloudinary in update method with getRealPath() error "Call to a member function getRealPath() on null"Laravel 在更新方法中通过 Cloudder 和 Cloudinary 上传图像,出现 getRealPath() 错误“调用成员函数 getRealPath() on null”
【发布时间】:2019-01-30 17:26:21
【问题描述】:

问题是我在创建产品时也使用了 cloudder,完成了。但是在编辑中,错误是“在 null 上调用成员函数 getRealPath()”

这是控制器 update() 方法

Cloudder::upload($request->file('images')->getRealPath(), $current_time);
    $product->images = Cloudder::getResult()['url'];
    $product->sale = $request->input('sale');
    $product->description = $request->input('description');
    $product->detail = $request->input('detail');
    $product->save();
    return redirect('/admin/product');

这里是视图,输入文件上传图片

                    <div class="row">
                        <label class="col-sm-2 label-on-left" for="inputSuccess">Upload image</label>
                        <div class="form-group">
                            <div class="row ml-1">
                                <div class="col-sm-2">
                                    <input type="file" name="images" class="mr-2" accept="image/*" onchange="readURL(this);">
                                    <span class="badge badge-green">Choose new image...</span>
                                    <img id="upload-image" src="#" alt="new image here" />
                                </div>
                                <div class="col-sm-2">
                                    <span class="badge badge-green">Previous Image</span>
                                    <img src="{{ $product->images }}" class="img-thumbnail" style="width: 150px; height: 150px;"/>
                                </div>
                                @if($errors->has('images'))
                                <label class="text-danger">*{{$errors->first('images')}}</label>
                                @endif
                            </div>
                        </div>
                    </div>

【问题讨论】:

    标签: laravel


    【解决方案1】:

    你可以使用getPathname,它是由laravel UploadedFile类扩展的SplFileInfo的方法

    Cloudder::upload($request->file('images')->getPathname(), $current_time);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-13
      • 1970-01-01
      相关资源
      最近更新 更多