I am using formData
to append image information and extract it into my API using php.
I append my data like this:
insertService(nom: string, fileToUpload: File): Promise<any> {
const url = 'http://localhost/Admin/src/api/api.php?action=insertService';
const formData: FormData = new FormData();
formData.append('image', fileToUpload);
const param = {nom: nom, image: formData};
console.log(param);
const request = this.http.post(url, param);
return request.toPromise();
}
So as you can see I append my data to 'image'.
And here I am trying to extract it
$nom = $_POST['nom'];
$image = $_POST['image'];
echo ('nom ' .$nom);
echo ('image :' .$image);
echo($_FILES["image"]["name"]);
$filetmp = $_FILES["image"]["tmp_name"];
$filename = $_FILES["image"]["name"];
$filepath = "../assets/img/" . $_FILES["image"]["name"];
move_uploaded_file($filetmp, $filepath);
$query = 'INSERT into etservice(nom_service,image_ser) values("' . $nom . '","' . $filepath . '")';
$result = $db->query($query);
if ($result === TRUE) {
$res = "Inserted'$nom' and image '$image' ";
echo json_encode($res);
} else {
echo json_encode("Error" . $query . "<br>" . $db->error);
}
It shows me this error
Notice: image : Array to string conversion
Can anybody help me please?