我正在尝试上传两个不同的文件,一个图像和一个 pdf 文件,每个文件都来自不同的输入,如下所示:
<div class="form-group" ng-class="libraries.error.img[0] ? 'has-error' : ''">
<label for="img">Image</label>
<input type="file" accept="image/*" ngf-select="" ngf-multiple="true" class="form-control" id="img" name="img" placeholder="Image" ng-model="libraries.library.img">
<p ng-if="libraries.error.img[0]" style="color: red">{{libraries.error.img[0]}}</p>
</div>
<div class="form-group" ng-class="libraries.error.document[0] ? 'has-error' : ''">
<label for="document">Document</label>
<input type="file" accept="application/pdf" ngf-select="" class="form-control" id="document" name="document" placeholder="Document" ng-model="libraries.library.document">
<p ng-if="libraries.error.document[0]" style="color: red">{{libraries.error.document[0]}}</p>
</div>
在服务文件中,我使用以下内容发送它:
store: function (library) {
console.log(library);
return Upload.upload({
url: 'api/libraries',
method: 'POST',
fields: {name: library.name, location: library.location},
file: [library.img, library.document]
});
},
但是当我尝试在服务器端获取文件时,如下所示:
return $_FILES;
我不断得到:
[] No Properties
但是,当我将文件更改为
file: library.img
意思是,我只传递一个文件,它有效。
我正在使用ng-file-upload
,AngularJS
服务器端是Laravel
有什么想法可以解决这个问题,允许将两个文件都发送到服务器?!