[英]Multi File upload using Angular js and php
We are taking over a site that is using Angular js for a form for data and multi-file upload (up to 4 files). 我们正在接管一个使用Angular js进行数据和多文件上传的表单的网站(最多4个文件)。
We are posting to a .php file. 我们正在发布到.php文件。 I have been able to separate and capture the field data - but can only seem to 'see' one file.
我已经能够分离和捕获现场数据-但似乎只能“看到”一个文件。 If I upload multiple files I 'see' only the last one added to the form.
如果我上传了多个文件,我只会看到添加到表单中的最后一个文件。
Can someone please help me to get the files using PHP? 有人可以帮我使用PHP获取文件吗?
Form HTML (for files): 表单HTML(用于文件):
<ul class="attachments">
<li ng-repeat="attachment in attachments" class="attachment">
{{attachment.name}}
<a href="" ng-click="removeAttachment(attachment)"><i class="btn-submit-att-x-hover-off"></i></a>
</li>
</ul>
<button type="button" class="attachments-button btn btn-default" ngf-select ngf-change="onFileSelect($files)" ngf-multiple="true" ng-if="attachments.length < 4">
<i class="btn-submit-attch"></i>Upload Attachments
</button>
Angular JS Code - for the files as I see: Angular JS代码-对于我所看到的文件:
$scope.attachments = [];
//onFileSelect adds file attachments to the $scope up to the
//configured maximum value.
$scope.onFileSelect = function ($files) {
var MAX_ATTACHMENTS = 4;
for(var i=0; i < $files.length; i++){
if($scope.attachments.length >= MAX_ATTACHMENTS){
break;
}
$scope.attachments.push($files[i]);
}
};
$scope.removeAttachment = function (attachment) {
var index = $scope.attachments.indexOf(attachment);
if (index > -1) {
$scope.attachments.splice(index, 1);
}
};
//POST form data
$scope.upload = Upload.upload({
url: 'forms/pressrelease.html',
method: 'POST',
data: $scope.model,
file: $scope.attachments,
fileFormDataName: "files"
})
.success(function (data, status, headers, config) {
alertSuccess("Your press release has been submitted successfully!");
$scope.showSuccess = true;
}
The only PHP code we've used that has given us anything back - but again - only 1, or the last file name is: 我们使用过的仅有的PHP代码可以使我们得到任何回报-但同样-仅1个,或者最后一个文件名是:
if(isset($_FILES['files'])){
$files = $_FILES['files'];
$sentfilename = $_FILES['files']['name'];
$email_body .= "I see files: $sentfilename<br />";
$tmpsentfile = $_FILES['files']['tmp_name'];
$i=0;
$getfile = $files[0];
$sentfilename = $getfile;
$sentfilesize = $_FILES['files']['size'];
$errormessage = $_FILES['files']['error'];
$email_body .= "I see files: $sentfilename<br />";
}
If anyone one can show us the PHP code we need to use to capture these uploaded files. 如果有人可以向我们展示PHP代码,则需要使用它们捕获这些上传的文件。
Thanks 谢谢
Create a names array and post the dynamic file names: 创建一个名称数组并发布动态文件名:
var names = []
foreach file:
names.push(files[i].name)
in upload: 在上传中:
method: 'POST',
data: $scope.model,
file: $scope.attachments,
fileFormDataName: names
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.