0

我想使用 curl 将图片上传到 Google picasa,我发现这行代码使用 curl 将图片上传到 Google picasa 但我不知道如何将其转换为 php 和 curl 才能使用它。

curl --silent --request POST --data-binary "@sweeping_the_rock.png" --header "Slug: Sweeping the rock" --header "Content-Type: image/png" --header "Authorization: GoogleLogin auth=ABCDEFG" "http://picasaweb.google.com/data/feed/api/user/brad.gushue/albumid/5113621341847124417" | tidy -xml -indent -quiet

$file = "C:/Users/Michael/Desktop/182178_271150652992340_118089494_n.jpg";
$postimg = "https://picasaweb.google.com/data/feed/api/user/userId/albumid/albumId";
$header = array("Content-Type: image/jpeg",
         "Content-Length: ".filesize($file),
         "Authorization: GoogleLogin auth=$token",
         "Slug: 182178_271150652992340_118089494_n.jpg"
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $postimg);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POSTFIELDS, file_get_contents($file));
$hasil = curl_exec($ch);
curl_close($ch);

来源:https ://developers.google.com/gdata/articles/using_cURL#media-support

4

1 回答 1

0

也许您没有正确发送文件。您需要为文件上传添加 CURL_OPT,以便对其进行 mime 编码和正确传输(发布文件上传是一种完全不同的表单编码,然后发送简单的发布数据)

http://php.net/manual/en/function.curl-setopt.php

CURLOPT_INFILE 上传时应读取传输的文件。

CURLOPT_INFILESIZE 将文件上传到远程站点时文件的预期大小(以字节为单位)。请注意,使用此选项不会阻止 libcurl 发送更多数据,因为发送的确切内容取决于 CURLOPT_READFUNCTION。

于 2012-08-28T22:13:43.060 回答