問題描述
前端用ajax把base64格式的圖片傳過來,能成功保存,但是不知為何會多生成一個圖片。
相關(guān)代碼
uploadImg () {
this.$http.post(this.$store.state.apiUrl + 'uploadImg', [
this.image
]).then(function (response) {
console.log(JSON.stringify(response.body));
}, function (response) {
console.log(JSON.stringify(response.body));
});
}
// php部分
define('UPLOAD_DIR', './uploads/');
$img = $this->request->post(0);
$start=strpos($img,',');
$img= substr($img,$start+1);
$img = str_replace(' ', '+', $img);
$data = base64_decode($img);
$fileName = UPLOAD_DIR . uniqid() . '.jpg';
$success = file_put_contents($fileName, $data);
$data=array();
if($success){
$data['status']=1;
$data['msg']= $img;
echo json_encode($data);
}else{
$data['status']=0;
$data['msg']='系統(tǒng)繁忙,請售后再試';
echo json_encode($data);
}
你期待的結(jié)果是什么?實際看到的錯誤信息又是什么?
多生成了右邊這個空白的圖片
- 3 回答
- 0 關(guān)注
- 721 瀏覽
添加回答
舉報
0/150
提交
取消