PHP CURL publish binary stream pictures

PHP CURL publish binary stream pictures


The module data in the project is updated by the PHP crawler. When a new image is detected, it needs to be uploaded to the cross-regional CDN back-to-origin server (static resource server). The person in charge of the server only provides an upload API.


  1. Save the picture locally and upload it with PHP CURL + new \CURLFile($path) (Disadvantage: IO operation)
  2. Simulate the splicing request data message, and send the picture directly to the upload API as a binary file āˆš
composer require ar414/curl-upload-binary-image

require_once '../vendor/autoload.php';

use Ar414\UploadBinaryImage;

$url = '';
$fields = [];
$fieldName = 'file';
$fileName = 'ar414.png';

$fileBody = file_get_contents('');

$ret = UploadBinaryImage::upload($url,$fields,$fieldName,$fileName,$fileBody);


  1. Revisit HTTP knowledge
  2. Upload files through postman, Google Chrome to view the sent request data
  3. Splicing request body
    • set Header multipart/form-data; boundary={md5(microtime())}
    • set Body Block Content-Type: application/octet-stream

#Support Author


Did you enjoyed the article ?
Subscribe to the newsletter šŸ‘Øā€šŸ’»

Be the first to know when I write something new! If you don't like emails, you can follow me on GitHub.