Is there anyone out there who is good with the PHP cURL functions and could possibly translate the following cURL call into the PHP functions?
I'm running into trouble replicating the "--data-binary @/var/www/html/images/request.png" portion into the various PHP options for cURL.
When I execute this on CLI, it works perfectly
curl -X POST --data-binary @/var/www/html/images/request.png http://127.0.0.1:4212/index/searcher
Here's my best try so far but it results in a corrupt image being uploaded:
<?php
$url = 'http://127.0.0.1:4212/index/searcher';
$header = array('Content-Type: multipart/form-data');
$fields = array('file' => '@/var/www/html/images/request.png');
$resource = curl_init();
curl_setopt($resource, CURLOPT_URL, $url);
curl_setopt($resource, CURLOPT_HTTPHEADER, $header);
curl_setopt($resource, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($resource, CURLOPT_BINARYTRANSFER, TRUE);
curl_setopt($resource, CURLOPT_POST, 1);
curl_setopt($resource, CURLOPT_POSTFIELDS, $fields);
$result = curl_exec($resource) ;
print_r($result);
curl_close($resource);
?>
Interesting part is the file in my system is 225873 bytes whereas after upload it becomes 226062.