基本的Auth curl图片上传

时间:2019-06-14 12:07:15

标签: curl

我的代码:

<?php

$url = 'https://www.example.com';


$username = 'xxxxxx';


$password = 'xxxxxx';


$ch = curl_init($url);

curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);  

$headers = array(
    'http'=>array(
        'method'=>"GET",
        'header' => "Authorization: Basic " . base64_encode("$username:$password")
    )
);

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$response = curl_exec($ch);

echo $response;

连接正常。但是我需要发送一个图像文件。我正在尝试:

    $post = array('file' => base64_encode(file_get_contents($_FILES['images']['tmp_name'])));


curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);

我正在将表单发布到此php文件中以获取图像文件。 没用请帮助我。

0 个答案:

没有答案