0

Hi i'm sending encoded base image string from android side and in server side i'm decoding the encoded image string and storing to folder, while saving to database i'm storing .JPG format. But the issue is if i upload .PNG image from android side it is storing in .JPG format but image is not visible in server side folder, and if i upload .JPG format it is visible in server side folder. Please help me out this problem.

PHP Code

 if(isset($_REQUEST['image1']))
    {
      $profile_picture = $_REQUEST['image1'];
      $target_path = "./upload/"."file"."_".time().".jpg";

      // **I want store multiple file forame** //

      $upload_img= "file"."_".time().".jpg";
      file_put_contents($target_path, base64_decode($profile_picture));
    }
    else
    {
        $upload_img = "image.png";
    }
Lokesh GP Loki
  • 101
  • 2
  • 15
  • What do you mean by storing in jpg format? It looks more that just the extension of the file is always jpg. But it then contains a png image. In the right png format! – greenapps Jan 19 '18 at 08:43
  • Let Android send the extension too. You can send as much parameters as you want. So your script can extract it. `$ext = $_REQUEST['ext']);` – greenapps Jan 19 '18 at 09:13

1 Answers1

0

You can send file extension(.jpg, .png) in webservice from android side and retrieve it in your back-end PHP side then store it in variable and use it dynamically.

Vatsal Desai
  • 169
  • 4
  • @Va I'm not getting in android side i'm sending only base64 encode string. and how to store dynamically. – Lokesh GP Loki Jan 19 '18 at 07:57
  • Try this link to retrieve image extension in php - https://stackoverflow.com/questions/6061505/detecting-image-type-from-base64-string-in-php – Vatsal Desai Jan 19 '18 at 09:31