te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>javascript - uploading multiple files with angularjs - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - uploading multiple files with angularjs - Stack Overflow

programmeradmin4浏览0评论

i want to upload multiple files using angular js, but it is like limited number of files and each with specific validation, hence cant use "multiple". Using multiple controls one for each file..

below is the sample code

var app = angular.module('plunker', []);

app.controller('MainCtrl', function($scope) {
  $scope.filelist = ['file1','file2']

});

app.directive("fileBind", function() {
  return function( scope, elm, attrs ) {
    elm.bind("change", function( evt ) {
      scope.$apply(function() {
        scope[ attrs.fileBind ] = evt.target.files;
      });
    });
  };
});

the corrposponding html is:

 <div ng-controller="MainCtrl">

      <div ng-repeat="myfile in filelist">
        <input type="file" file-bind="files" />
      </div>

      <div ng-repeat="file in files">
        <pre>{{ file | json }}</pre>
      </div>

    </div>

I have also made a plunker for it:

but this is not working... if i use $index or anything to store all the files uploaded, the directive stops working...

any help is appriciated

i want to upload multiple files using angular js, but it is like limited number of files and each with specific validation, hence cant use "multiple". Using multiple controls one for each file..

below is the sample code

var app = angular.module('plunker', []);

app.controller('MainCtrl', function($scope) {
  $scope.filelist = ['file1','file2']

});

app.directive("fileBind", function() {
  return function( scope, elm, attrs ) {
    elm.bind("change", function( evt ) {
      scope.$apply(function() {
        scope[ attrs.fileBind ] = evt.target.files;
      });
    });
  };
});

the corrposponding html is:

 <div ng-controller="MainCtrl">

      <div ng-repeat="myfile in filelist">
        <input type="file" file-bind="files" />
      </div>

      <div ng-repeat="file in files">
        <pre>{{ file | json }}</pre>
      </div>

    </div>

I have also made a plunker for it: http://plnkr.co/edit/DF2WYU

but this is not working... if i use $index or anything to store all the files uploaded, the directive stops working...

any help is appriciated

Share Improve this question edited Jun 11, 2013 at 7:01 Mahen asked Jun 11, 2013 at 6:43 MahenMahen 531 gold badge2 silver badges10 bronze badges 2
  • 2 And your question is? – hakre Commented Jun 11, 2013 at 6:47
  • sorry wasnt too explicit about the question – Mahen Commented Jun 11, 2013 at 7:07
Add a ment  | 

2 Answers 2

Reset to default 8

Not sure where the problem is but I have put together a simple/light angular directive with polyfill for browsers not supporting HTML5 FormData here:

https://github./danialfarid/angular-file-upload

It is very similar to what you do here using a directive listening to change event. Then you can call added prototype to $http "uploadFile" to upload that file to the server via ajax. For IE it would load up a flash file to simulate the same thing.

Here is the working demo: http://angular-file-upload.appspot./

<script src="angular.min.js"></script>
<script src="angular-file-upload.js"></script>

<div ng-controller="MyCtrl">
  <input type="text" ng-model="myModelObj">
  <input type="file" ng-file-select="onFileSelect($files)" >
</div>

controller:

$http.uploadFile({
    url: 'my/upload/url',
    data: {myObj: $scope.myModelObj},
    file: $file
  }).then(function(data, status, headers, config) {
    // file is uploaded successfully
    console.log(data);
  }); 

I'm not sure about your intention looking the code (sorry not much time...) anyway a single html tag input-file can contain a list of files,see https://developer.mozilla/en-US/docs/Web/API/FileList

Given that you can try with this answer appending more files to the FormData

发布评论

评论列表(0)

  1. 暂无评论