The following script works:
move_uploaded_file($_FILES['file']['tmp_name'], $filename);
echo exec('curl -X POST --data-binary @' . $filename . ' http://remote.api:8888/index/add');
Following doesn't:-
We will be disabling exec() soon and will be doing plenty of hardening so the above solution will not work.
I tried the following:
move_uploaded_file($_FILES['file']['tmp_name'], $filename);
$filetype = $_FILES['file']['type'];
$ch = curl_init('http://remote.api/index/add');
curl_setopt($ch, CURLOPT_PORT, 8888);
curl_setopt($ch, CURLOPT_POST, TRUE);
$cFile = curl_file_create($filename, $filetype, $_FILES['file']['name']); // php5.5+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, ['file' => $cFile]);
$x = curl_exec($ch);
curl_close($ch);
The server does not respond to this workaround.
What am I missing? Please note I am using php 5.5 thus curl_create_file
Thank you for all the help :)