0

I am a Java guy and don't know about PHP. I am sending byte array of image to the PHP server and I want the PHP code to convert that byte array to image and save the image to a folder and return path of that file so that I can store it to a database

Java side:

  String image = Base64.encodeToString(chosenImage.getFileThumbnail().getBytes(),
                                Base64.NO_WRAP);

PHP Side:

$datax = $data['image'];
$datax = base64_decode($datax);

$im = imagecreatefromstring($data);



            move_uploaded_file($im , 'upload/' .'abc.png' );
            $path = 'http://xxxx/cc/zz/tt/' . $new_file_name;

        } 
maxshuty
  • 9,708
  • 13
  • 64
  • 77

1 Answers1

0

Java already encoded the raw image data in base64 so in PHP you don't need to use imagecreatefromstring (unless you want to further manipulate it) since it is already an image.

This code is probably sufficient:

$datax = base64_decode($data['image']);
file_put_contents('upload/abc.png', $datax);
drew010
  • 68,777
  • 11
  • 134
  • 162