title: Send file using multipart/form-data request in php
body: <p>I have image resource stored in variable which I need to send to server using its http API and PHP. I have to send request with content type multipart/form-data. So, I need to make similiar request as when form with file input and enctype=multipart/form-data attribute is sent.
  I tried this:</p>
  
  <pre><code>&lt;?php
  $url = 'here_is_url_for_web_API';
  $input = fopen('delfin.jpg','r');       
  $header = array('Content-Type: multipart/form-data');
  $resource = curl_init();
  curl_setopt($resource, CURLOPT_URL, $url);
  curl_setopt($resource, CURLOPT_USERPWD, "user:password");
  curl_setopt($resource, CURLOPT_HTTPAUTH, CURLAUTH_ANYSAFE);
  curl_setopt($resource, CURLOPT_HTTPHEADER, $header);
  curl_setopt($resource, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($resource, CURLOPT_BINARYTRANSFER, true );
  curl_setopt($resource, CURLOPT_INFILESIZE, 61631);
  curl_setopt($resource, CURLOPT_INFILE, $input);
  $result = curl_exec($resource);
  curl_close($resource);
  var_dump($result);
  ?&gt;
  </code></pre>
  
  <p>I don't know how exactly response should look like but this returns:
  http status 405
  and error report is: The specified HTTP method is not allowed for the requested resource ().</p>