Or does PHP not allow this? I have read it is possible using PUT but the server is expecting POST only.
How to send a file using Curl? To upload a file, use the -d command-line option and begin data with the @ symbol. If you start the data with @, the rest should be the file's name from which Curl will read the data and send it to the server. Curl will use the file extension to send the correct MIME data type.
Uploading files using CURL is pretty straightforward once you've installed it. Several protocols allow CURL file upload including: FILE, FTP, FTPS, HTTP, HTTPS, IMAP, IMAPS, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, and TFTP. Each of these protocols works with CURL differently for uploading data.
cURL Specify Content-Type The Content-Type entity in the header specifies the type of media of the resource we are sending. The media type is also commonly known as the MIME Type. To specify the Content-Type in a cURL request, we can use the -H flag. For example, let us send MIME Type of application/JSON.
--data-binary is a curl SPECIFIC flag for curl itself. it has nothing to do with HTTP web services call specifically, but it's how you "POST" data to the call in the HTTP BODY instead of in the header WHEN using curl.
cURL has already support for streams, try curl --help | grep binary
and you will get:
--data-binary DATA HTTP POST binary data (H)
An example:
curl -v -XPOST http://example:port/path --data-binary @file.tar
-H "Content-Type: application/octet-stream"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With