ローカル サーバーから youtube.com に動画をアップロードしようとしています。
以下のフォームを使用すると、動画が YouTube にアップロードされます。ログイン後に YouTube から応答を取得し、以下の形式で応答を採用することができます。
<form action="<?php echo( $response->url ); ?>?nexturl=<?php echo( urlencode( $nexturl ) ); ?>" method="post" enctype="multipart/form-data">
<p class="block">
<label>Upload Video</label>
<span class="youtube-input">
<input id="file" type="file" name="file" />
</span>
</p>
<input type="hidden" name="token" value="<?php echo( $response->token ); ?>"/>
<input type="submit" value="Upload Video" />
</form>
しかし、以下のようにcurlで同じことをしようとすると、うまくいきません..何か提案はありますか??
$file_name_with_full_path = $video_path; //$video_path is like /path/to/abc.mp4
$post = array('file'=>'@'.$file_name_with_full_path, 'token' => $response->token,);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$response->url."?nexturl=".urlencode($nexturl));
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$result=curl_exec ($ch);
curl_close ($ch);
echo $result;
die();