fileinput image upload

//Upload pictures when adding products. When editing products, the pictures should also be displayed. The method is a convenient if judgment. If the currently edited product has the path of images, assign the absolute path.

//There is $data['images'] in the code. $data is the data of the current product, and $data['images'] is the image path of the current product stored in the database

$("#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();
});



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324814471&siteId=291194637