title: Upload Image to Server PHP Android
body: <p>I am lost right now with trying to upload an image to my server. I am able  to take the picture and get my location on the Android device. I have the follow code to upload the file to the server:</p>
  
  <pre><code>    public Boolean postFunction(File image) {
      String tag = "postFunction";
  
      HttpClient httpclient = new DefaultHttpClient();
      HttpPost httppost = new HttpPost(UPLOAD_URL);
  
      try {
          MultipartEntity entity = new MultipartEntity();
  
          entity.addPart("type", new StringBody("photo"));
          entity.addPart("data", new FileBody(image));
          httppost.setEntity(entity);
          HttpResponse response = httpclient.execute(httppost);
          Log.i(tag, "picture was uploaded " + response.toString());
          return true;
  
      } catch (ClientProtocolException e) {
          Log.e(tag, "Client: " + e.toString());
          return false;
      } catch (IOException e) {
          Log.e(tag, "IO: " + e.toString());
          return false;
      }
  }
  </code></pre>
  
  <p>I pass the image file to this function and it does the upload. However the error lies on the server end I believe. </p>
  
  <p>Here is my PHP code: </p>
  
  <pre><code>      public function upload() {
          //$type = $this-&gt;input-&gt;post('type');
          //$data = $this-&gt;input-&gt;post('data');
  
          $base = $_REQUEST['data'];
  
          echo $base;
  
  // base64 encoded utf-8 string
  
          $binary = base64_decode($base);
  
  // binary, utf-8 bytes
  
          header('Content-Type: bitmap; charset=utf-8');
  
  // print($binary);
  //$theFile = base64_decode($image_data);
  
          $file = fopen('./test.jpg', 'wb');
  
          fwrite($file, $binary);
  
          fclose($file);
  
          echo '&lt;img src=test.jpg&gt;';
      }
  </code></pre>
  
  <p>The file gets touched but still remain blank. Am I missing something here? Please help, I tried Googling this but came up with different results that did not help me much.</p>