fileinput 图片上传

//添加商品的时候上传图片,当编辑商品的时候,要把图片也显示出来,做法为下便的if判断,如果当前编辑的商品有images的路径,则赋值 绝对路径。

//代码中有个$data['images']  $data为当前商品的数据,$data['images']为当前商品存入数据库的图片路径

$("#kv-explorer").fileinput({
'theme': 'fa',
language: 'zh',
uploadUrl: "{{ route('uploadImg','brand') }}",
deleteUrl: "{{ route('deleteImg') }}",
allowedFileExtensions: ['jpg', 'jpeg', 'gif', 'png'],
overwriteInitial: false,
initialPreviewAsData: true,
maxFileCount: 1,
uploadExtraData: {"_token": "{{ csrf_token() }}"},
deleteExtraData: {"_token": "{{ csrf_token() }}"},
initialPreview: [
@if($data['images'])
"http://" + "{{ $data['images'] }}",
@endif
],
initialPreviewConfig: [
@if($data['images'])
{
key: "{{ $data['images'] }}"
},
@endif
],
}).on('fileuploaded', function (event, data, key) {
$('form').append('<input type="hidden" name="images" value="' + data['response'].data + '">');
}).on('filepredelete', function () {
$(":input[name='images']").remove();
}).on('filesuccessremove', function () {
$(":input[name='images']").remove();
});



posted @ 2018-04-25 09:31  沐屋  阅读(189)  评论(0编辑  收藏  举报