1
我在laravel应用程序中使用blueimp文件上传插件,但似乎没有工作,我也包含了所有必需的库。blueimp maxNumberOfFiles在Laravel中不工作
以下是相关的代码:
<script src="/assets/js/jquery.ui.widget.js"></script>
<!-- The Iframe Transport is required for browsers without support for XHR file uploads -->
<script src="/assets/js/jquery.iframe-transport.js"></script>
<!-- The basic File Upload plugin -->
<script src="/assets/js/jquery.fileupload.js"></script>
<script src="/assets/js/file_upload.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/blueimp-file-upload/9.12.6/js/jquery.fileupload-process.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/blueimp-file-upload/9.12.6/js/jquery.fileupload-validate.min.js"></script>
<script src="/assets/js/styling.js"></script>
jQuery代码:
function file_upload() {
$('.fileupload').fileupload({
url: 'http://localhost:8000/Ad/file_upload',
"_token": "{{ csrf_token() }}",
dataType: 'json',
formData: {fileName: '7',
title:'this',
desc:'that'
},
maxNumberOfFiles: 2,
acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i,
maxFileSize: 1024 * 1024,
messages: {
maxFileSize: 'File exceeds maximum allowed size of 1MB',
},
fail: function (e, data) {
/* $.ajax({
url: 'http://localhost:8000/Ad/file_upload',
dataType: 'json',
data: {file: data.files[0].name},
type: 'DELETE'
});*/
},
done: function (e, data) {
//alert(JSON.stringify(data.result));
$.each(data.result.files, function (index, file) {
if (imageArray.indexOf(file.name) == -1) {
imageArray.push(file.name);
// alert("filename:"+file.name);
}
$('.files').html($('.files').html()+'<span class="upload col-md-2" id="'+file.name+'"><img src="/uploads/'+file.name+'"/><input class="cross" type="button" value="X" onclick="deleteImage(\''+(file.name)+'\');" style="display:none;"></span>');
});
$('.upload').hover(
function() {
$(this).find(".cross").show();
}, function() {
$(this).find(".cross").hide();
}
);
var progress = 0;
$('.progress .progress-bar').css('transition','none');
$('.progress .progress-bar').css('width',progress);
},
progressall: function (e, data) {
var progress = parseInt(data.loaded/data.total * 100, 10);
$('.progress .progress-bar').css('transition','width .6s ease');
$('.progress .progress-bar').css(
'width',
progress + '%'
);
}
}).prop('disabled', !$.support.fileInput)
.parent().addClass($.support.fileInput ? undefined : 'disabled').on('fileuploadprocessalways', function (e, data) {
var currentFile = data.files[data.index];
if (data.files.error && currentFile.error) {
// there was an error, do something about it
$('.image-error').html($('.image-error').html()+'<span class="alert alert-danger">'+currentFile.error+'</span>').show();
setTimeout(function() {
$(".image-error").hide('blind', {}, 300);
$('.alert-danger').remove();
}, 3000);
}
});
}
我都试过,包括jquery.fileupload-ui.js LIB但之后没有任何作品。
什么是你所得到的错误? –
没有错误,只是maxNumberOfFiles不工作我能够上传超过2个文件 –