title: How to do cURL php using AJAX to make a live request?
body: <p>I am currently using this code:</p>
  
  <pre><code>    &lt;form enctype="multipart/form-data" method="post" action="upload_img.php"&gt;
      Choose your file here:
      &lt;input name="uploaded_file" type="file"/&gt;
      &lt;input type="submit" value="Upload It"/&gt;
      &lt;/form&gt;
      &lt;?
      if( isset($_FILES['uploaded_file']) )
  {
      $IMGUR_API_KEY = 'APIKEY';
      $filename = $_FILES['uploaded_file']['tmp_name'];
      $handle = fopen($filename, "r");
      $data = fread($handle, filesize($filename));
  
      //$data is file data
      $pvars   = array('image' =&gt; base64_encode($data), 'key' =&gt; $IMGUR_API_KEY);
      #$pvars   = array('key' =&gt; $IMGUR_API_KEY);
      $timeout = 30;
      $curl    = curl_init();
  
      curl_setopt($curl, CURLOPT_URL, 'http://api.imgur.com/2/upload.xml');
      #curl_setopt($curl, CURLOPT_URL, 'http://api.imgur.com/2/gallery.xml');
      curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);
      curl_setopt($curl, CURLOPT_POST, 1);
      curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($curl, CURLOPT_POSTFIELDS, $pvars);
      $xml = curl_exec($curl);
      $xmlsimple = new SimpleXMLElement($xml);
      echo '&lt;img height="180" src="';
      echo $xmlsimple-&gt;links-&gt;original;
      echo '"&gt;';
  
      curl_close ($curl);
      }
  ?&gt;
  </code></pre>
  
  <p>Which works perfectly fine, but I need to use this as a form separate to insert multiple fields. In the end, all I need to do is make an AJAX cURL request to upload the photo then get the imgur.com url to the direct image. How would I go about making this form a submit that does this via AJAX so I can stay on this page... Any help would be appreciated, it doesn't have to be fully written, but a spark of an idea. I have no clue where I'm going with this sofar.</p>
  
  <p>Thanks,
  HackyWackee</p>