FireMonkey sending to a webform: Image fails to upload

  

I’m writing an app in FireMonkey which takes pictures and submits them to a website. The pictures are being taken. They save when I want them to, I can see them in Astro File Manager on the correct path.

The problem starts when I try to upload them. I’m trying to use this FireMonkey code (on Android) to upload a picture:

procedure TTabbedForm.PixSender(PixPath: String; PixID: String);
var
TheResponse : String;
multiStream : TMultipartFormData;
begin
try
multiStream := TMultiPartFormData.Create;
multiStream.AddField(‘car’, Edit_Login_Username.Text);
multiStream.AddField(‘ssn’, Edit_Login_Password.Text);
multiStream.AddFile(‘theimage’, PixPath + PixID);
multiStream.AddField(‘submit’, ‘submit’);
NetHTTPRequest1.URL := ‘http://www.hdwp.com/ba/test.php’;
NetHTTPRequest1.Post(‘http://www.hdwp.com/ba/test.php’,multiStream);
TheResponse := NetHTTPRequest1.Execute().ContentAsString();
Panel_Send.Visible := False;
TabControl_Detail.Visible := True;
except
TheResponse := ‘Upload failed.’;
end;
ShowMessage(PixPath + PixID + ‘ | ‘ + NetHTTPRequest1.URL + ‘ | ‘ + TheResponse);
end;

I see this:

The webpage I’m sending to:

<?php
$target_dir = “images/”;
$target_file = $target_dir . basename($_FILES[“theimage”]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
//if(isset($_POST[“submit”])) {
$check = getimagesize($_FILES[“tmp_name”]);
if($check !== false) {
echo “File is an image – ” . $check[“mime”] . “.”;
$uploadOk = 1;
} else {
echo “File is not an image.”;
$uploadOk = 0;
}

if ($uploadOk == 0) {
echo “Sorry, your file was not uploaded.”;
} else {
if (move_uploaded_file($_FILES[“tmp_name”], $target_file)) {
echo “The file “. basename( $_FILES[“name”]). ” has been uploaded.”;
} else {
echo “Sorry, there was an error uploading your file.”;
}
}
?>

All help appreciated.

Comments are closed.