Witam,
Mam problem z YouTube Data API. Muszę wysłać coś takiego:
Kod
POST /feeds/api/users/default/uploads HTTP/1.1
Host: uploads.gdata.youtube.com
Authorization: AuthSub token="<authentication_token>"
GData-Version: 2
X-GData-Client: <client_id>
X-GData-Key: key=<developer_key>
Slug: <video_filename>
Content-Type: multipart/related; boundary="<boundary_string>"
Content-Length: <content_length>
Connection: close

--<boundary_string>
Content-Type: application/atom+xml; charset=UTF-8

API_XML_request
--<boundary_string>
Content-Type: <video_content_type>
Content-Transfer-Encoding: binary

<Binary File Data>
--<boundary_string>--

szczegóły na: http://code.google.com/intl/pl/apis/youtub..._uploading.html

za pomocą fsocketopen() można to wysłać w ten sposób:
  1. <?php
  2. $boundary = self::generateBoundaryString();
  3.                $out = "POST /feeds/api/users/default/uploads HTTP/1.1r\n";
  4.                $out .= "Host: uploads.gdata.youtube.comr\n";
  5.                $out .= "Authorization: AuthSub token=\"$this->token\"r\n";
  6.                $out .= "GData-Version: 2r\n";
  7.                $out .= "X-GData-Client: ".$this->client_id."r\n";
  8.                $out .= "X-GData-Key: key=".$this->developer_key."r\n";
  9.                $out .= "Slug: ".$this->movie->slug."r\n";
  10.                $out .= "Content-Type: multipart/related; boundary=\"".$boundary."\"r\n";
  11.                $out .= "Content-Length: <content_length>r\n";
  12.                $out .= "Connection: Closer\nr\n";
  13.                //XML with description
  14.                $out .="--".$boundary."r\n";
  15.                $out .="Content-Type: application/atom+xml; charset=UTF-8r\n";
  16.                $out .= self::MakeMovieDescriptionXML();
  17.                $out .="--".$boundary."r\n";
  18.                //File data
  19.                $out .="Content-Type: video/mp4r\n";
  20.                $out .="Content-Transfer-Encoding: binaryr\n";
  21.                //Read file
  22.                  $fh = fopen($file_url, "rb");
  23.                $data = fread($fh, filesize($file_url));
  24.                fclose($fh);
  25.                $out .= $data;
  26.                $out .="--".$boundary."r\n";
  27.                try {
  28.                    if(fwrite($fp, $out)) {
  29.                        while (!feof($fp)) {
  30.                            $response =  fgets($fp, 1024);
  31.                                $dom = new DomDocument();
  32.                                $dom->LoadHtml($response);
  33.                            $link = $dom->getElementByTagName("link");
  34.                            $value = $link->item(0)->getAttribute('href');
  35.                            echo($value);
  36.                        }
  37.                           fclose($fp);        
  38.                    }else{
  39.                        throw new Exception("Cannot Send data");
  40.                    }    
  41.                }catch(Exception $e) {
  42.                    printf("Error on %s:%d %s\n", $e->getFile(), $e->getLine(), $e->getMessage());
  43.                }
  44. ?>

Teraz pojawia się pytanie jak zastąpić wysyłanie danych z frwite() na cUrl?

Pozdrawiam,
mmx3

Zastanawiam się jeszcze nad jednym, czy czasem nie władować całości danych do nagłówka pliku