Php Jqueryfileupload BlueImp使用sendAPI进行多文件上载

Php Jqueryfileupload BlueImp使用sendAPI进行多文件上载,php,jquery,Php,Jquery,我试图通过一个ajax调用发送多个文件。 问题是我不能得到我的进度工作得到这条线 TypeError: data.context is undefined data.context.find('input').val(progress).change(); 不知道如何使用sendAPI>管理每个tpl的进度?我搜索了很多尝试不同的事情。这样做的基本原因是我想要一个ajax请求,并在该请求完成后拥有控制权 MYHTML <form id="upload" method="post"

我试图通过一个ajax调用发送多个文件。 问题是我不能得到我的进度工作得到这条线

TypeError: data.context is undefined
data.context.find('input').val(progress).change();
不知道如何使用sendAPI>管理每个tpl的进度?我搜索了很多尝试不同的事情。这样做的基本原因是我想要一个ajax请求,并在该请求完成后拥有控制权

MYHTML


 <form  id="upload" method="post" action="upload.php"    enctype="multipart/form-data">
      <div>

            <div id="drop">
               Drop Here <span style="color:white;text-transform:none;font-size: 13px">     OR    <span>

                     <a>Browse</a>
                     <input type="file" name="upl[]" multiple/>


                     </div>

                     <ul>
                        <!-- The file uploads will be shown here -->
                     </ul>
                     </div>
                     </form>



MY JQUERY 

// Initialize the jQuery File Upload plugin
       $('#upload').fileupload({
          disableImageResize: /Android(?!.*Chrome)|Opera/
                  .test(window.navigator && navigator.userAgent),
           imageMaxWidth: 100,


          imageMaxHeight: 100,
          maxFileSize: 5000000,
          acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i,
          dropZone: $('#drop'),
          add: function(e, data) {

                     var type = data.files[0].type;
             var size = data.files[0].size;
             if ( type == 'image/jpeg' || type == 'image/png' || type == 'image/gif' ) {

                if(size<=350000000)
                {
                //   var preview = '<img src="' + URL.createObjectURL(data.files[0]) + '"/>';
                var tpl = $('<li class="working"><input type="text" value="0" data-width="48" data-height="48"' +
                        ' data-fgColor="#0788a5" data-readOnly="1" data-bgColor="#3e4043" /><div class="preview"></div><p></p><span></span></li>');
                tpl.find('p').text(data.files[0].name).append('<i>' + formatFileSize(data.files[0].size) + '</i>');
                loadImage(data.files[0],
                        function(img) {
                           tpl.find('.preview').html(img);
                        },
                        {
                           minWidth: 80,
                           minHeight: 60, maxWidth: 80, maxHeight: 60, contain: true} // Options
                );


                // Add the HTML to the UL element
                data.context = tpl.appendTo(ul);

                // Initialize the knob plugin
                tpl.find('input').knob();

                // Listen for clicks on the cancel icon
                tpl.find('span').click(function() {

                   if (tpl.hasClass('working')) {
                      jqXHR.abort();
                   }

                   tpl.fadeOut(function() {
                      tpl.remove();
                   });

                });

               myfiles.push(data.files[0]);

             } else{ 
              noty({type:'error',text: 'file exceeds limit of 350Kb'}); 
             }//check for file type

          } else 
             {
                 noty({type:'error',text: 'Invalid file type.Please make sure image has valid extension jpeg|gif|jpg'});  
             }


    //         $('#post_picture').on('click',function(){
    //            
    //          
    //             
    //            var jqXHR = data.submit().success(function (result, textStatus, jqXHR) {ar.push(result)});
    //            
    //            
    //             tpl.fadeOut(function() {
    //                  tpl.remove();
    //               });
    //            $('#post_picture').off('click');
    //           
    //            
    //            
    //         });






          },
          complete:function(e,data)
          {


          },
           progress: function(e, data) {

             // Calculate the completion percentage of the upload
             var progress = parseInt(data.loaded / data.total * 100, 10);

             // Update the hidden input field and trigger a change
             // so that the jQuery knob plugin knows to update the dial
             data.context.find('input').val(progress).change();

             if (progress == 100) {
                data.context.removeClass('working');
             }
          },
          fail: function(e, data) {
             // Something has gone wrong!
             data.context.addClass('error');
          }




       });

       $(document).on('click','#post_picture',function(){
          alert('asdas');
     $('#upload').fileupload('send', {files: myfiles});
       });
MYHTML
在这里下车或者
浏览
我的JQUERY //初始化jQuery文件上传插件 $('#upload').fileupload({ disableImageResize:/Android(?。*Chrome)| Opera/ .test(window.navigator&&navigator.userAgent), 图像最大宽度:100, 图像最大高度:100, 最大文件大小:5000000, acceptFileTypes:/(\.\/)(gif | jpe?g | png)$/i, dropZone:$(“#drop”), 添加:功能(e、数据){ var type=data.files[0]。类型; var size=data.files[0]。大小; 如果(类型=='image/jpeg'| |类型=='image/png'| |类型=='image/gif'){
如果(尺寸我就是这样做的,为什么现在没有人回答:)

var myfiles=[];
//初始化jQuery文件上传插件
$('#upload').fileupload({
disableImageResize:/Android(?。*Chrome)| Opera/
.test(window.navigator&&navigator.userAgent),
图像最大宽度:100,
图像最大高度:100,
最大文件大小:5000000,
acceptFileTypes:/(\.\/)(gif | jpe?g | png)$/i,
dropZone:$(“#drop”),
添加:功能(e、数据){
var type=data.files[0]。类型;
var size=data.files[0]。大小;
如果(类型=='image/jpeg'| |类型=='image/png'| |类型=='image/gif'){
如果(尺寸)
 var myfiles = [];


   // Initialize the jQuery File Upload plugin
   $('#upload').fileupload({
      disableImageResize: /Android(?!.*Chrome)|Opera/
              .test(window.navigator && navigator.userAgent),
      imageMaxWidth: 100,
      imageMaxHeight: 100,
      maxFileSize: 5000000,
      acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i,
      dropZone: $('#drop'),
      add: function(e, data) {




         var type = data.files[0].type;
         var size = data.files[0].size;
         if (type == 'image/jpeg' || type == 'image/png' || type == 'image/gif') {

            if (size <= 350000000)
            {
               //   var preview = '<img src="' + URL.createObjectURL(data.files[0]) + '"/>';
               var tpl = $('<li class="working"><input type="text" value="0" data-width="48" data-height="48"' +
                       ' data-fgColor="#0788a5" data-readOnly="1" data-bgColor="#3e4043" /><div class="preview"></div><p></p><span></span></li>');
               tpl.find('p').text(data.files[0].name).append('<i>' + formatFileSize(data.files[0].size) + '</i>');
               loadImage(data.files[0],
                       function(img) {
                          tpl.find('.preview').html(img);
                       },
                       {
                          minWidth: 80,
                          minHeight: 60, maxWidth: 80, maxHeight: 60, contain: true} // Options
               );


               // Add the HTML to the UL element
               data.context = tpl.appendTo(ul);

               // Initialize the knob plugin
               tpl.find('input').knob();
               // Listen for clicks on the cancel icon
               tpl.find('span').click(function() {


               if (tpl.hasClass('working'))
               {

               data='';

               }

                  tpl.fadeOut(function() {
                     tpl.remove();
                  });

               });

               // myfiles.push(data.files[0]);

            } else {
               noty({type: 'error', text: 'file exceeds limit of 350Kb'});
            }//check for file type

         } else
         {
            noty({type: 'error', text: 'Invalid file type.Please make sure image has valid extension jpeg|gif|jpg'});
         }


         $('#post_picture').on('click', function() {


               if(data!='')
               {
            var jqXHR = data.submit().success(function(result, textStatus, jqXHR) {
            });
               }


            tpl.fadeOut(function() {
               tpl.remove();
            });
            $('#post_picture').off('click');
         });






      },
      stop: function(e) {
         console.log(myfiles);
      },
      progress: function(e, data) {

         // Calculate the completion percentage of the upload
         var progress = parseInt(data.loaded / data.total * 100, 10);
         // Update the hidden input field and trigger a change
         // so that the jQuery knob plugin knows to update the dial
         data.context.find('input').val(progress).change();
         if (progress == 100) {
            data.context.removeClass('working');
         }
      },
      fail: function(e, data) {
         // Something has gone wrong!
         data.context.addClass('error');
      }




   }).on('fileuploaddone', function(e, data) {

     myfiles.push(data.result);

   });