这是控制器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>
答案 0 :(得分:0)
您可以使用getPathname
,这是laravel SplFileInfo
类扩展的UploadedFile
方法
Cloudder::upload($request->file('images')->getPathname(), $current_time);