$ _POST [image]卷曲上传?

时间:2019-06-20 13:57:26

标签: php image curl upload

$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 (output) = data:image/png;base64,iVBOsdfscb.......

问题:

$data = array (
    'file' => $image
); 

工作方式(成功):

$fname = $_FILES['image']['tmp_name'];
$cfile = new CURLFile(realpath($fname));

$data = array (
    'file' => $cfile
);  

但是我有$_POST[image]和ajax。不是$_FILES[image]

我的语言不好。抱歉,请帮助我。

0 个答案:

没有答案