我的代码:
<?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文件中以获取图像文件。 没用请帮助我。