title: HTML JPG Upload to PHP Script to POST RESTful Web Service
body: <p>I have a need for auser to upload two images and then for the images to be base64 enocded and posted to a restful webservice. </p>
  
  <p>I am able to encode and post the images and get a successful response when i use a file on the server but what i need to do is use the image being uploaded by the end user dynamically. </p>
  
  <p>Here is my form:</p>
  
  <pre><code> &lt;form action="dcams.php" enctype="multipart/form-data" method="post"&gt;
      &lt;input name="MAX_FILE_SIZE" type="hidden" value="30000"&gt; Send this
      file: &lt;input name="front" type="file"&gt; And this file: &lt;input name=
      "back" type="file"&gt; &lt;input type="submit" value="Send Files"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Here is my PHP Script that works with a static file on server but I need to get the file contents from the posted images: </p>
  
  <pre><code> &lt;?php
  header('Content-type: application/json');
  
  $imagedata_front = file_get_contents("front.jpg");
  $base64_front    = base64_encode($imagedata_front);
  
  $imagedata_back = file_get_contents("back.jpg");
  $base64_back    = base64_encode($imagedata_back);
  
  $url = "https://xxxxxxxxxxxx.com";
  
  $data        = array(
  "user" =&gt; "",
  "pass" =&gt; "",
  "target" =&gt; array(
      "license" =&gt; array(
          "front" =&gt; "$base64_front",
          "back" =&gt; "$base64_back",
          "state" =&gt; "CT"
      ),
      "age" =&gt; "21+"
  ),
  "service" =&gt; ""
  );
  $data_string = json_encode($data);
  
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
  curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_FAILONERROR, 1);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
  curl_setopt($ch, CURLOPT_TIMEOUT, 200);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  
  $result = curl_exec($ch);
  echo "$result";
  ?&gt; 
  </code></pre>
  
  <p>What I want to do is something like this: </p>
  
  <pre><code>$imagedata_front = $_FILES['front'];
  $base64_front    = base64_encode($imagedata_front);
  
  $imagedata_back = $_FILES['back';
  $base64_back    = base64_encode($imagedata_back);
  </code></pre>
  
  <p>But this does not work. Does anyone know the proper way to do this? </p>