Sayuj Raghavan

Sayuj Raghavan

  • NA
  • 52
  • 6.5k

Webservices in PHP for picture upload

Apr 18 2016 6:37 AM
I am working on android app's web service for picture uploading. So far ,I have attempted to work on with the below  code.
 
    
     <?php
        include('db.php');
        $jobseeker_id =isset($_POST['JobseekerID']) ? mysql_real_escape_string($_POST['JobseekerID']) : "";
      // Get image string posted from Android App
      $base=isset($_POST['image']) ? mysql_real_escape_string($_POST['image']) : "";
     // Get file name posted from Android App
     $filename=isset($_POST['filename']) ? mysql_real_escape_string($_POST['filename']) : "";
     echo $base;
    // Decode Image
    $binary=base64_decode($base);
    header('Content-Type: bitmap; charset=utf-8');
    //Images will be saved under 'images' folder in the server
       chmod("images",777);
       $file = fopen('images/'.$filename,'wb');

     // Create File
       fwrite($file, $binary);

        fclose($file);
        if($file)
        {
           $q=mysql_query("UPDATE documents SET crop_pic=' $binary' where user_id='$jobseeker_id'")or die(mysql_error());

             $response["ProfilePic"][]= array("Status"=>"1","Message" =>"Profile Pic is uploaded");
echo die(json_encode($response));
         }
      else
       {

         $response["ProfilePic"][]= array("Status"=>"0","Message" =>"Profile Pic uploding failure");

       }


       ?>

         In the above code, I am not getting the image decoded  from the android app successfully, image is getting into the folder ,but the image is not getting displayed perfectly. I doubt its mistake of base64_decode function . I am still not able to find why the image is not getting displayed. Hoping for some help to rectify it or point out the logical or syntactical error in the above code.