【发布时间】:2018-08-13 22:32:46
【问题描述】:
我正在尝试通过资源发送图像并在 php 文件中恢复但我没有成功,这是我的 JS 文件:
//* AJAX *//
startAsyncNews: function(){
if(this.sendimage){
var formdata = new FormData();
formdata.append("file",this.contentnew.imageFile );
console.log(this.contentnew.imageFile);
}
// POST /someUrl
this.$http.post('controllers/newsController.php', {
data:{action : this.accion_new, data_new: this.contentnew , imgf : formdata}
}).then(response => {
}, response => {
console.log("error");
});
},
imageSelect: function($event){
this.sendimage=true;
this.contentnew.imageFile =$event.target.files[0];
}
当我使用console.log = console.log (this.contentnew.imageFile) 时,它会正确显示图像的属性,也就是说,它可以很好地发送文件,但是当我在 php 中接收它并执行 vardump 时,我得到了这个对象(stdclass)# 3 (0) no properties no properties and with json_decode / encode 我把它弄空了,也试试
headers: {
'content-type': 'multipart/form-data'
}
但它会产生以下错误:
multipart/form-data POST 中缺少边界
【问题讨论】:
标签: javascript php vue.js