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 でエンコードされ、正しく転送されるようにする必要があります (ファイルのアップロードの POST は、フォームのエンコードと単純な投稿データの送信とはまったく異なります)。

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

CURLOPT_INFILE アップロード時に転送を読み取るファイル。

CURLOPT_INFILESIZE ファイルをリモート サイトにアップロードするときのファイルの予想サイズ (バイト単位)。このオプションを使用しても libcurl がさらにデータを送信するのを止めないことに注意してください。送信されるデータは正確には CURLOPT_READFUNCTION に依存するためです。

于 2012-08-28T22:13:43.060 に答える