I am currently sending an byte [] from my frontend into my domain and PHP-code. The byte array that I am sending is named "photo" and it is sent like a System.Text.Encoding.UTF8, "application/json". My goal is to get the byte [] into an image and then upload it my domainfolder (that already exists) do I need to get the image_name and the image_tmp_name from that byte [] in order to do this? I am a bit uncertain on how exactly I should get this to work.
I currently have this code:
<?php
$value = json_decode(file_get_contents('php://input'));
if(!empty($value)) {
print_r($value);
}
?>
With this code the print gives me a huge line of text containing the byte [].
How do I now get the image_name and image_tmp_name from this byte []? My goal is to upload the image on my domainmap (named photoFolder that already exists) with a code looking something like this:
$image_tmp_name = ""; //I currently do not have this value
$image_name = ""; //I currently do not have this value
if(move_uploaded_file($image_tmp_name, "photoFolder/$image_name")) {
echo "image successfully uploaded";
}
How i send it:
static public async Task <bool> createPhotoThree (byte [] imgData)
{
var httpClientRequest = new HttpClient ();
var postData = new Dictionary <string, object> ();
postData.Add ("photo", imgData);
var jsonRequest = JsonConvert.SerializeObject(postData);
HttpContent content = new StringContent(jsonRequest, System.Text.Encoding.UTF8, "application/json");
var result = await httpClientRequest.PostAsync("http://myadress.com/test.php", content);
var resultString = await result.Content.ReadAsStringAsync ();
return true;
}