2016-06-24 12 views
0

Ich habe,verwendet, um Dateien hochzuladen, Dateien werden hochgeladen alles funktioniert gut.Wie Datei-Upload in angular-Datei-Upload zu begrenzen

Nun, ich habe Einschränkung hinzufügen, dass Benutzer kann mehr dann 5 Bilder hochladen und bei einem Schuss einzigen Datei sollte nicht in der Lage laden Wie ist es möglich,

Unten ist mein Code

-Controller

'use strict'; 
angular.module('Modulename') 
    .controller('AppController', ['$scope', 'FileUploader', function($scope, FileUploader) { 
     var uploader = $scope.uploader = new FileUploader({ 
      url: site_url+'upload.php' 
     }); 

     // FILTERS 

     uploader.filters.push({ 
      name: 'imageFilter', 
      fn: function(item /*{File|FileLikeObject}*/, options) { 
       var type = '|' + item.type.slice(item.type.lastIndexOf('/') + 1) + '|'; 
       return '|jpg|png|jpeg|bmp|gif|'.indexOf(type) !== -1; 
      } 
     }); 

     // CALLBACKS 

     uploader.onWhenAddingFileFailed = function(item /*{File|FileLikeObject}*/, filter, options) { 
      console.info('onWhenAddingFileFailed', item, filter, options); 
     }; 
     uploader.onAfterAddingFile = function(fileItem) { 
      console.info('onAfterAddingFile', fileItem); 
      // fileItem.upload(); 
     }; 
     uploader.onAfterAddingAll = function(addedFileItems) { 
      console.info('onAfterAddingAll', addedFileItems); 
     }; 
     uploader.onBeforeUploadItem = function(item) { 
      console.info('onBeforeUploadItem', item); 
     }; 
     uploader.onProgressItem = function(fileItem, progress) { 
      console.info('onProgressItem', fileItem, progress); 
     }; 
     uploader.onProgressAll = function(progress) { 
      console.info('onProgressAll', progress); 
     }; 
     uploader.onSuccessItem = function(fileItem, response, status, headers) { 
      console.info('onSuccessItem', fileItem, response, status, headers); 
     }; 
     uploader.onErrorItem = function(fileItem, response, status, headers) { 
      console.info('onErrorItem', fileItem, response, status, headers); 
     }; 
     uploader.onCancelItem = function(fileItem, response, status, headers) { 
      console.info('onCancelItem', fileItem, response, status, headers); 
     }; 
     uploader.onCompleteItem = function(fileItem, response, status, headers) { 
      console.info('onCompleteItem', fileItem, response, status, headers); 
     }; 
     uploader.onCompleteAll = function() { 
      console.info('onCompleteAll'); 
     }; 

     console.info('uploader', uploader); 
    }]); 

View-Bereich

<section ng-switch-when="1" class="form-section {{animationClass}} wow" ng-class="{{animationClass}}" ng-controller ="AppController" nv-file-drop="" uploader="uploader"> 
     <div class="form-section-block"> 
      <h3 class="heading text-center">Upload photos</h3> 

      <!-- Upload demo area --> 
      <style> 
      .my-drop-zone { border: dotted 3px lightgray; } 
      .nv-file-over { border: dotted 3px red; } /* Default class applied to drop zones on over */ 
      .another-file-over-class { border: dotted 3px green; } 

      html, body { height: 100%; } 

      canvas { 
       background-color: #f3f3f3; 
       -webkit-box-shadow: 3px 3px 3px 0 #e3e3e3; 
       -moz-box-shadow: 3px 3px 3px 0 #e3e3e3; 
       box-shadow: 3px 3px 3px 0 #e3e3e3; 
       border: 1px solid #c3c3c3; 
       height: 100px; 
       margin: 6px 0 0 6px; 
      } 
     </style> 
      <div class="row"> 

       <div class="col-md-3"> 

        <h3>Select files</h3> 

        <div ng-show="uploader.isHTML5"> 
         <!-- 3. nv-file-over uploader="link" over-class="className" --> 
         <div class="well my-drop-zone" nv-file-over="" uploader="uploader" options="{autoUpload :'true'}"> 
          Base drop zone 
          <input type="file" nv-file-select="" uploader="uploader" multiple /> 
         </div> 

        </div> 

       </div> 

       <div class="col-md-9" style="margin-bottom: 40px"> 


        <table class="table"> 
         <thead> 
          <tr> 
           <th width="50%">Name</th> 
           <th ng-show="uploader.isHTML5">Size</th> 
           <th ng-show="uploader.isHTML5">Progress</th> 
           <th>Status</th> 
           <th>Actions</th> 
          </tr> 
         </thead> 
         <tbody> 
          <tr ng-repeat="item in uploader.queue"> 
           <td> 
            <strong>{{ item.file.name }}</strong> 
            <!-- Image preview --> 
            <!--auto height--> 
            <!--<div ng-thumb="{ file: item.file, width: 100 }"></div>--> 
            <!--auto width--> 
            <div ng-show="uploader.isHTML5" ng-thumb="{ file: item._file, height: 100 }"></div> 
            <!--fixed width and height --> 
            <!--<div ng-thumb="{ file: item.file, width: 100, height: 100 }"></div>--> 
           </td> 
           <td ng-show="uploader.isHTML5" nowrap>{{ item.file.size/1024/1024|number:2 }} MB</td> 
           <td ng-show="uploader.isHTML5"> 
            <div class="progress" style="margin-bottom: 0;"> 
             <div class="progress-bar" role="progressbar" ng-style="{ 'width': item.progress + '%' }"></div> 
            </div> 
           </td> 
           <td class="text-center"> 
            <span ng-show="item.isSuccess"><i class="glyphicon glyphicon-ok"></i></span> 
            <span ng-show="item.isCancel"><i class="glyphicon glyphicon-ban-circle"></i></span> 
            <span ng-show="item.isError"><i class="glyphicon glyphicon-remove"></i></span> 
           </td> 
           <td nowrap> 
            <button type="button" class="btn btn-success btn-xs" ng-click="item.upload()" ng-disabled="item.isReady || item.isUploading || item.isSuccess"> 
             <span class="glyphicon glyphicon-upload"></span> Upload 
            </button> 
            <button type="button" class="btn btn-warning btn-xs" ng-click="item.cancel()" ng-disabled="!item.isUploading"> 
             <span class="glyphicon glyphicon-ban-circle"></span> Cancel 
            </button> 
            <button type="button" class="btn btn-danger btn-xs" ng-click="item.remove()"> 
             <span class="glyphicon glyphicon-trash"></span> Remove 
            </button> 
           </td> 
          </tr> 
         </tbody> 
        </table> 

        <div> 
         <div> 
          Queue progress: 
          <div class="progress" style=""> 
           <div class="progress-bar" role="progressbar" ng-style="{ 'width': uploader.progress + '%' }"></div> 
          </div> 
         </div> 
         <button type="button" class="btn btn-success btn-s" ng-click="uploader.uploadAll()" ng-disabled="!uploader.getNotUploadedItems().length"> 
          <span class="glyphicon glyphicon-upload"></span> Upload all 
         </button> 
         <button type="button" class="btn btn-warning btn-s" ng-click="uploader.cancelAll()" ng-disabled="!uploader.isUploading"> 
          <span class="glyphicon glyphicon-ban-circle"></span> Cancel all 
         </button> 
         <button type="button" class="btn btn-danger btn-s" ng-click="uploader.clearQueue()" ng-disabled="!uploader.queue.length"> 
          <span class="glyphicon glyphicon-trash"></span> Remove all 
         </button> 
        </div> 

       </div> 

      </div> 
      <!-- Upload demo area --> 




      <div class="col-md-4 col-sm-4 label-block"></div> 
      <div class="col-md-6 col-sm-8 signup-full-column"> 
      <div class="stepToggle-btn"> 
       <span class=""> 
        <a href="#" class="btn btn-success up" data-toggle="tooltip" tooltip-placement="top" uib-tooltip="Previous Step" ng-click="previousStep()"><i class="fa fa-angle-up" aria-hidden="true"></i></a> 
       </span> 
        <button type="submit" class="btn btn-success down" data-toggle="tooltip" tooltip-placement="top" uib-tooltip="Next Step" ><i class="fa fa-angle-down" aria-hidden="true"></i> 
       </button> 
      </div> 
      </div> 
      <div class="clearfix"></div> 
     </div> 
    </section> 
+0

meinst du, sie nicht mehr als 5 Dateien gleichzeitig hochladen, oder sie nach 5 Uploads stoppen? – M21B8

+0

auf einmal hochladen eine einzelne Datei und nicht in der Lage mehr als 5 Dateien hochladen –

Antwort

0

können Sie die Filter-Warteschlange Limit verwenden für dieses

var Uploader = new Fileuploader ({ queueLimit: 1 });

<element nv-file-drop filters="queueLimit"></element> 
+0

Wir können das behalten, aber zuerst müssen wir beschränken, einzelne Datei auf Einzelaufnahme hochzuladen –