0

I get base64 string from my android appliation using which the php script saves it to the directory everything works fine for png. except i need the script to work for all image types At android side i have httpservlet extended class and using which i send a get request with a variable containing base64 string. So all we have is a base64 string nothing else at server side Can you help me with that?? This is my php code

<?php

 $imgstr = $_REQUEST['string'];


      // Decode the data
$data = base64_decode($imgstr);

$im = imagecreatefromstring($data);
if ($im !== false) {
header('Content-Type: image/png');
imagepng($im);

$success = file_put_contents("img/abc". uniqid().".png", $data);
imagedestroy($im);
if ($success) {
    echo 'yes yes yes';
}
} else {
echo 'An error occurred.';

} ?>

7
  • Did you check to see if it's sending a $_file from the submission form? Commented Jul 5, 2014 at 18:29
  • There is no submission form i am sending through android using httprequest. just one variable string of bas64 Commented Jul 5, 2014 at 18:51
  • How do you pass data, when it's not being passed through a type of form? Is an applet that passes data to your PHP server still not a type of form? Commented Jul 5, 2014 at 19:29
  • At android side i have httpservlet extended class and using which i send a get request with a variable containing base64 string. So all we have is a base64 string nothing else at server side Commented Jul 6, 2014 at 6:41
  • Was your problem solved? Commented Jul 9, 2014 at 19:32

1 Answer 1

1

Ok so what i did was that i just calculated the mime type before encoding to base64 and sent that as a variable too

This is how i did it

 public static String getMimeType(String url) {
    String type = null;
    String extension = MimeTypeMap.getFileExtensionFromUrl(url);
    if (extension != null) {
        MimeTypeMap mime = MimeTypeMap.getSingleton();
        type = mime.getMimeTypeFromExtension(extension);
    }
    return type;
}   

   mimetype = getMimeType(picturePath);
   String temp[] = mimetype.split("/");
   as.add(new BasicNameValuePair("mime", temp[1]));

After this as was sent to server along with image.

Sign up to request clarification or add additional context in comments.

1 Comment

So you researched it on your own. I thought it would be sent to the server as a $_FILE, but I guess not.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.