doutong6814 2019-06-20 13:57
浏览 58

$ _POST [image] curl上传?

$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.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 stata安慰剂检验作图但是真实值不出现在图上
    • ¥15 c程序不知道为什么得不到结果
    • ¥40 复杂的限制性的商函数处理
    • ¥15 程序不包含适用于入口点的静态Main方法
    • ¥15 素材场景中光线烘焙后灯光失效
    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题