如何使用vue.js发送文件?
以下代码对我不起作用:
<span title="Upload" class="badge badge-info">
<input type="file" id="file" name="file" @change="uploadData" class="archive" > <i id="iarchive" class="fa fa-upload"></i>
</span>
Run Code Online (Sandbox Code Playgroud)
当我做console.log(this.request.file)我得到FILE [object File]。
这是.js:
uploadData: function(e) {
var files = e.target.files[0];
this.request.action = 'upload';
this.request.file = files;
console.log("FILE "+this.request.file);
this.$http.post('data/getData.php', {
data: this.request,
headers: {
'Content-Type': 'multipart/form-data'
}
}
).then(function(response) {
console.log("RESPONSE: "+response.body);
}, function(response) {
alert("error");
});
return false;
}
Run Code Online (Sandbox Code Playgroud)
但是在PHP中,我无法获取文件,响应为:{} No properties。
PHP代码:
$request = json_decode(file_get_contents('php://input'));
$req = $request->data;
echo json_encode($req->file)
Run Code Online (Sandbox Code Playgroud) 我尝试使用 Google API,但是,当我运行它时,它显示以下错误:
GuzzleHttp\Exception\RequestException: cURL error 60: SSL certificate problem: u
nable to get local issuer certificate (see http://curl.haxx.se/libcurl/c/libcurl
-errors.html) in C:\wamp64\www\apigmail\vendor\guzzlehttp\guzzle\src\Handler\Cur
lFactory.php on line 187
Run Code Online (Sandbox Code Playgroud)
我使用 WAMP -Server PHP v 7.0.13