How to download a file with PHP, curl and HTTP POST by streaming the file?

Let's say that I have a large file that I want HTTP POST for a web service using PHP and curls. The file has more memory that I can allow to use PHP.

Basically, I'm looking for a way to stream the contents of a file directly for curling without reading the entire file in memory.

I have success using multi-page POST and PUT, but not loading "binary data" using POST.

What I want to achieve in PHP is what this command does:

 $ curl -X POST -H "Content-Type: image/jpeg" \
       --data-binary "@large.jpg" "http://example.com/myservice"

Tried a lot of options with curl_setopt like INFILE, POSTFIELDS, Content-Type header, but no luck.

It works with multipart, but I need a raw POST request, no multiparts:

$post['file'] = "@large.jpg";
curl_setopt($c, CURLOPT_POSTFIELDS, $post);
+3
source
1

PHP/CURL CURLOPT_READFUNCTION, chunk-by-chunk .

, C: http://curl.haxx.se/libcurl/c/post-callback.html

+3

All Articles