$image = $_POST["image"];
$url = 'https://example.com/upload';
$username = 'R142AE3VsiZSBbfDw==';
$password = 'eEfasfMHzs8e2rJkWv41DkiE8iwo0=';
$additionalHeaders = array(
'http'=>array(
'method'=>"POST",
'header' => "Authorization: Basic " . base64_encode("$username:$password")
)
);
$data = array (
'file' => $image
);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array($additionalHeaders));
curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$return = curl_exec($ch);
curl_close($ch);
echo $return;
image file doesn't upload. curl connection ok.
$image (output) = data:image/png;base64,iVBOsdfscb.......
problem :
$data = array (
'file' => $image
);
how it works (it is successful) :
$fname = $_FILES['image']['tmp_name'];
$cfile = new CURLFile(realpath($fname));
$data = array (
'file' => $cfile
);
but i have $_POST[image]
with ajax. Not $_FILES[image]
my language is bad. sorry, please help me.