【发布时间】:2015-05-03 04:43:28
【问题描述】:
我想使用https://github.com/danialfarid/ng-file-upload/ 进行文件上传。我正在尝试使用 $_FILES 全局数组来捕获上传的文件。当文件的内容被发送到服务器时,PHP 似乎无法捕获上传的文件元数据(文件名等)。所以 $_FILES 是空的。顺便说一句,我应该将文件和数据属性都设置为file
$scope.upload = function (files) {
if (files != null && files[0]) {
var file = files[0];
console.log(file);
file.upload = Upload.http({
url: 'rest/file/',
data:file,
fileName:'test',
file: file
});
file.upload.then(function (response) {
file.result = response.data;
}, function (response) {
if (response.status > 0)
$scope.errorMsg = response.status + ': ' + response.data;
});
file.upload.progress(function (evt) {
file.progress = Math.min(100, parseInt(100.0 * evt.loaded / evt.total));
});
}
}
HTML 标记:
<p>
<label for="background">Background</label>
<input ngf-select ngf-change="upload($files)" accept="image/*"
ng-model="form.background"
name="background" type="file"/>
<img ng-show="form.background[0] != null" ngf-thumbnail="form.background[0]" class="thumb"/>
<span class="meter" ng-show="form.background[0].progress >= 0">
<span style="width:{{form.background[0].progress}}%"
ng-bind="form.background[0].progress + '%'"
class="ng-binding">
</span>
</span>
</p>
【问题讨论】:
-
嗨@phpst,你找到解决办法了吗?
-
我不记得了。我搬到blueimp.github.io/jQuery-File-Upload