I'm trying to send an image using vue-resource and retrieve it in a php file but I have not succeeded, this is my JS file:
//* 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];
}
When I use the console.log = console.log(this.contentnew.imageFile);
it shows me the properties of the image correctly, that is to say it is sending the file well, but when I receive it in php and I do vardump I get like this object(stdclass)#3 (0) no properties
no properties and with json_decode / encode me it is empty, also try without
headers: {
'content-type': 'multipart/form-data'
}
But it generates the following error:
Missing boundary in multipart / form-data POST