Uploading Image from android to PHP server

Uploading Image from android to PHP server:

Android Upload Image To Server Using PHP MySQL is showing error.

In my app i am uploading an image from my device to a local web server… after executing the code a .jpg file gets created in the server but it does not gets opened.

 

- Android Upload Image To Server Using PHP MySQL



** $_POST['image'] = here only encoded image dada is sent form andoid device.


//If image is posted then this block will work only
if( !empty($_POST['image']) ){
    $image_data = $_POST['image']; //$data_base64;
    
    $data_base64_encoded = $image_data;
    $data_base64_encoded = urldecode($data_base64_encoded); //$data_base64; 

    //image extension 
    $data_extn = 'jpg';  

   //new image name 
   $rand = (rand(10,10000)); 
   $new_file_name  = time().$rand.'.'.$data_extn; 
   $new_file       = 'image/'.$new_file_name; //decode & upload image file 

   $data_base64_decoded = base64_decode($data_base64_encoded);  
   $new_success    = file_put_contents($new_file, $data_base64_decoded);

   if($new_success){ 
       //Record  Data if needed. 
    }
}else{ 
   echo Please choose a file.
}


** It will work on postman also.
** From postman have to sent the encoded image data.