Using this code you can upload and image using curl with third party role
/*Send Page*/
$filename = covertImage($filename);
$fields = array(
'customer_name' => 'Gulshan Sharma',
'filename' => $filename,
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'http:example.com/upload/');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "webapp");
//curl_setopt($ch, CURLOPT_POSTFIELDS,$fields);
// in real life you should use something like:
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields));
// receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, "xxx:xxx");
$server_output = curl_exec ($ch);
curl_close ($ch);
function covertImage($path){
$type = pathinfo($path, PATHINFO_EXTENSION);
$data = file_get_contents($path);
$base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
return $base64;
}
/*RecivePage*/
$filename = base64_to_jpeg($_POST['filename']);
echo $filename;
function base64_to_jpeg($base64_string) {
$upload_path = '/hosted-libraries/temp/';
$upload_path = $_SERVER['DOCUMENT_ROOT'] . $upload_path;
$newImg = uniqid();
$img = str_replace('data:image/png;base64,', '', $base64_string);
$img = str_replace(' ', ' ', $img);
$data = base64_decode($img);
$file = $upload_path . $newImg . '.png';
$success = file_put_contents($file, $data);
if($success)
return $file;
else
FALSE;
}