title: How to upload a file with PHP, curl and HTTP POST by streaming the file?
body: <p>Lets say I have a large file that I want to HTTP POST to a webservice using PHP and curl. The file is larger than the amount of memory I can let PHP use.</p>
  
  <p>Basically I'm looking for a way to stream the content of a file directly to curl, without reading the entire file into memory.</p>
  
  <p>I have success using multipart POSTs and PUT, but not "binary data" upload with POST.</p>
  
  <p>What I want to achieve in PHP is what this command line does:</p>
  
  <pre><code> $ curl -X POST -H "Content-Type: image/jpeg" \
         --data-binary "@large.jpg" "http://example.com/myservice"
  </code></pre>
  
  <p>Tried a lot of options with curl_setopt, such as INFILE, POSTFIELDS, Content-Type header, but no luck.</p>
  
  <p>It works with multipart though, but I need a raw POST request, no multiparts:</p>
  
  <pre><code>$post['file'] = "@large.jpg";
  curl_setopt($c, CURLOPT_POSTFIELDS, $post);
  </code></pre>