blueimp maxNumberOfFiles在Laravel中无效

时间:2016-10-28 08:13:39

标签: laravel file-upload jquery-plugins blueimp

我在laravel应用程序中使用blueimp文件上传插件但它似乎不起作用,我也包含了所有必需的库。

以下是相关代码:

<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但是没有任何作用。

2 个答案:

答案 0 :(得分:0)

尝试更改值

maxNumberOfFiles: 2,

答案 1 :(得分:0)

删除&#34;最大文件数&#34;来自Jquery。

打开Uploadhandler.php并在选项中插入以下代码:

 'max_number_of_files' => 300, //300 files for example

比它完成了。