如何在 AngularJS 中上传多个文件
How to Upload Multiple file in AngularJS
我使用 ngFileUpload 上传文件,但它只能上传 1 个文件。
我要上传图片文件和 PDF 文件。如何上传多个文件?
请帮帮我。
(function () {
'use strict';
var app = angular.module('pageApp', ['ngFileUpload']);
app.controller('MyCtrl', ['$scope', 'Upload', '$timeout', function ($scope, Upload, $timeout) {
$scope.uploadPic = function (file) {
file.upload = Upload.upload({
url: 'save_form.php',
data: {
file: file,
username: $scope.username
},
});
file.upload.then(function (response) {
$timeout(function () {
file.result = response.data;
});
}
};
}]);
})();
<form name="myForm">
Profile Picture: <input type="file" ngf-select="" ng-model="picFile" name="file" ngf-accept="'image/*'">
<br>
Resume(.pdf): <input type="file" ngf-select="" ng-model="resumeFile" name="fileResume">
<br>
<button ng-disabled="!myForm.$valid" ng-click="uploadPic(picFile)">Submit</button>
</form>
如果您想同时上传多个文件,您可以组合这两个输入字段并向输入标签添加多个属性。请确保您的后端可以接受多个文件/支持以下功能。
<form name="myForm">
Picture & Resume: <input type="file" ngf-select=""
ng-model="picFile" name="file" ngf-pattern="'image/*,application/pdf'" multiple>
<br>
<button ng-disabled="!myForm.$valid" ng-click="uploadPic(picFile)">Submit</button>
</form>
我使用 ngFileUpload 上传文件,但它只能上传 1 个文件。
我要上传图片文件和 PDF 文件。如何上传多个文件?
请帮帮我。
(function () {
'use strict';
var app = angular.module('pageApp', ['ngFileUpload']);
app.controller('MyCtrl', ['$scope', 'Upload', '$timeout', function ($scope, Upload, $timeout) {
$scope.uploadPic = function (file) {
file.upload = Upload.upload({
url: 'save_form.php',
data: {
file: file,
username: $scope.username
},
});
file.upload.then(function (response) {
$timeout(function () {
file.result = response.data;
});
}
};
}]);
})();
<form name="myForm">
Profile Picture: <input type="file" ngf-select="" ng-model="picFile" name="file" ngf-accept="'image/*'">
<br>
Resume(.pdf): <input type="file" ngf-select="" ng-model="resumeFile" name="fileResume">
<br>
<button ng-disabled="!myForm.$valid" ng-click="uploadPic(picFile)">Submit</button>
</form>
如果您想同时上传多个文件,您可以组合这两个输入字段并向输入标签添加多个属性。请确保您的后端可以接受多个文件/支持以下功能。
<form name="myForm">
Picture & Resume: <input type="file" ngf-select=""
ng-model="picFile" name="file" ngf-pattern="'image/*,application/pdf'" multiple>
<br>
<button ng-disabled="!myForm.$valid" ng-click="uploadPic(picFile)">Submit</button>
</form>