如何通过PHP发送Base64编码的图像?

如何通过PHP发送Base64编码的图像?,php,curl,base64,Php,Curl,Base64,我想通过PHP/cURL将图像作为Base64编码字符串发送,而不是使用file\u get\u contents部分。 怎么做 $headers = array("Host" => "http://api.tumblr.com/", "Content-type" => "application/x-www-form-urlencoded", "Expect" => ""); $params = array("data" => array(file_get_conten

我想通过PHP/cURL将图像作为Base64编码字符串发送,而不是使用
file\u get\u contents
部分。 怎么做

$headers = array("Host" => "http://api.tumblr.com/", "Content-type" => "application/x-www-form-urlencoded", "Expect" => "");

$params = array("data" => array(file_get_contents("http://www.example.com/photo/happyholidays.jpg")),"type" => "photo");

oauth_gen("POST", "http://api.tumblr.com/v2/blog/$blogname/post", $params, $headers);

$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, "TestApp");
curl_setopt($ch, CURLOPT_URL, "http://api.tumblr.com/v2/blog/$blogname/post");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );

curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    "Authorization: " . $headers['Authorization'],
    "Content-type: " . $headers["Content-type"],
    "Expect: ")
);

谢谢

您必须以任何方式读取图像才能获取图像的字节数据。只有这样,才能轻松地将字节数据转换为base64。据我所知,您不能直接从链接(图像)发送(http post)字节


如果您不想使用文件获取内容来读取图像,则使用卷曲获取图像的字节数据。

因为它只有一个图像,所以不会有任何区别。另外,$params中的“数据”如何处理取决于函数oauth_gen(),这里不太清楚!
$params = array("data" => base64_encode(file_get_contents("http://www.example.com/photo/happyholidays.jpg")),"type" => "photo");