I am trying to send text data and a Base64encoded image string to my test server. The data is sent in pairs.
ArrayList<NameValuePair> params = new ArrayList<>();
params .add(new BasicNameValuePair("ownName", text1));
params .add(new BasicNameValuePair("phone", text4));
params.add(new BasicNameValuePair("email", text2));
params .add(new BasicNameValuePair("petName", text5));
params .add(new BasicNameValuePair("zipCode", text3));
params .add(new BasicNameValuePair("image", imageString));
The image is encoded into a string(where 'b' is my compressed bitmap) and sent to the server with the text items.
imageString = Base64.encodeToString(b, Base64.DEFAULT);
I add the text information to my database and I want to store the image on the server. I'm certain that my PHP script on my server is wrong. I have tried some of the suggestions from other posts with the same question, but I have not been successful. The image name shows up in the directory that I specify, but it is 0kb in size and cannot be opened. At the moment, I'm trying this type of format for my PHP side
$data = $_POST["image"];
list($type, $data) = explode(',', $data);
$data = base64_decode($data);
file_put_contents('../image1.jpg', $data[1]);
I have tried many variations of this but none have worked. Am I parsing the right portion of the POST image? I appreciate any help/input.
Thanks.