title: How to send an image to deviantsart rest API with PHP
body: <p>Here, one of the responses (#3) tells: </p>
  
  <blockquote>
    <p><a href="http://deviantsart.com" rel="nofollow noreferrer">http://deviantsart.com</a> has a public and easy to use API just HTTP POST the image to their domain and you will get a JSON with the URL</p>
  </blockquote>
  
  <p>Here is the URL:</p>
  
  <p><a href="https://stackoverflow.com/questions/1469092/are-there-any-image-hosting-services-with-a-public-api/21364938">Are there any image hosting services with a public API?</a></p>
  
  <p>The only instructions are basically </p>
  
  <blockquote>
    <p>"Upload using our public REST API: POST <a href="http://deviantsart.com" rel="nofollow noreferrer">http://deviantsart.com</a>
    yourimage.jpg </p>
    
    <p>JSON-Result:</p>
  
  <pre><code>{ "url" : "urltoimage" }"
  </code></pre>
  </blockquote>
  
  <p><strong>Nice, but, how can I make it programmable?</strong></p>
  
  <p>Here is my code:</p>
  
  <pre><code>//the file was uploaded by a simple html form
  
  if ($_POST) { //submit
      $tmp = array_merge($_POST);
  
      $r = new HttpRequest('http://deviantsart.com', HttpRequest::METH_POST);
      $r-&gt;addPostFile($tmp['img']); //tmp has post vars
      echo $r-&gt;getUrl();
  
      try {
          echo $r-&gt;send()-&gt;getBody();
          exit();
      } catch (HttpException $ex) {
          echo $ex;
          exit();
      }
  }
  </code></pre>
  
  <p>LAST EDIT: please, dont care about my code, try to solve with your own. I just want see how it works. Many thanks!</p>