我正在尝试通过阅读一些教程来学习angularJS,在这个阶段我正在尝试创建一个包含多个上传文件的表单(2个单独的文件)。我想过使用ng-file-upload插件。
我遇到了以下问题,
1)如何传递2个单独文件上传的值?
<input type="file" name="profile_pic" ng-file-select="onFileSelect">
<input type="file" name="document" ng-file-select="onFileSelect2">
2)如何将文件分别捕获到PHP文件中?
HTML
<form enctype="multipart/form-data" method="post" >
<input type="text" ng-model="name">
<input type="text" ng-model="age">
<input type="text" ng-model="title">
<input type="file" name="profile_pic" ng-file-select="onFileSelect">
<input type="file" name="document" ng-file-select="onFileSelect2">
<input type='button' ng-click='onFormSubmit' value='Submit'>
</form>
的Javascript
angular.module('myApp', ['ngFileUpload']);
var MyCtrl = [ '$scope', 'Upload', function($scope, Upload) {
$scope.onFileSelect = function(file) {
Upload.upload({
url: 'api/upload-data.php',
method: 'POST',
file: file,
data: {
'name': $scope.name,
'age' : $scope.age ,
'title' : $scope.title ,
}
})
};
}];
PHP
//does not show the files
var_dump($_FILES);
$filename = $_FILES['file']['name'];
move_uploaded_file( $_FILES['file']['tmp_name'] , '/uploads');
//shows the input texts
var_dump($_POST)