Hi guys, I spend the whole morning on this class, but i can't find the problem. The idea is that you can upload video's to youtube using this class. What works: [list] [*]The login part (signing in and get redirected to /index [*]The add part (completing in the form and get redirected to step 2) [/list] What doesn't want to work: [list] [*]Posting the video to the youtube servers[quote]I search the post url out of the form in step 2 (i got it somewhere out of a javascript code). I'm working with the flash posting url because the normal posting url gives a 404 error (and actually the flash one is giving a 400, which is better i guess)[/quote] [/list] Here is the class i use: [code]<?php /********************************************************/ /* */ /* Copyright 2006 Exclamation Media Group */ /* */ /* All classes are written by Andreas Creten */ /* www.andreascreten.be */ /* */ /* */ /********************************************************/ // ------------------- CLASS YOUTUBE ------------------- // // with this class you can upload a video to youtube // // // // how does it work: // // - initialize the class: // // $up = new youtube(); // // - login with your own username and password: // // $up->login('username', 'password'); // // - make a new movie handler: // // $up->add('title', 'description', 'keyw');// // - upload the movie to the handle: // // $up->upload('themovieurl'); // // // // ----------------------------------------------------- // // Copyright 2006 Andreas Creten // // ----------------------------------------------------- // class youtube { var $connection; // set urls for youtube var $login_url = "http://www.youtube.com/signup"; var $upload_form_url = "http://www.youtube.com/my_videos_upload"; var $upload_post_url; var $cookie_location = 'cookie.txt'; var $post_vars = array(); function __construct() { // init curl session $this->connection = curl_init(); //return header curl_setopt($this->connection, CURLOPT_HEADER, 1); //return data as string curl_setopt($this->connection, CURLOPT_RETURNTRANSFER,1); // follow redirects curl_setopt($this->connection, CURLOPT_FOLLOWLOCATION,1); // connection timeout curl_setopt($this->connection, CURLOPT_CONNECTTIMEOUT,10); // set cookies curl_setopt($this->connection, CURLOPT_COOKIESESSION , 1); curl_setopt($this->connection, CURLOPT_COOKIEJAR, $this->cookie_location); } function login($username, $password) { // set dynamic form vars $this->postvarAdd('username',$username); $this->postvarAdd('password',$password); // set static form vars $this->postvarAdd('action_login', "Log In"); $this->postvarAdd('current_form', "loginForm"); // set curl options curl_setopt($this->connection, CURLOPT_URL, $this->login_url); // set curl post vars curl_setopt($this->connection, CURLOPT_POST, 1); curl_setopt($this->connection, CURLOPT_POSTFIELDS, $this->postvarString()); // delete form vars which are not needed anymore $this->postvarDel('username', 'password', 'action_login', 'current_form'); // execute curl return curl_exec($this->connection); } function add($title, $description = null, $keywords = null, $categories = 1, $privacy = "public", $language = "EN") { // set dynamic form vars $this->postvarAdd('field_myvideo_title', $title); $this->postvarAdd('field_myvideo_descr', $description); $this->postvarAdd('field_myvideo_keywords', $keywords); $this->postvarAdd('field_myvideo_categories', $categories); $this->postvarAdd('language', $language); $this->postvarAdd('field_privacy', $privacy); // set static form vars $this->postvarAdd('field_command', 'myvideo_submit'); $this->postvarAdd('action_upload', 'Continue ->'); // set curl options curl_setopt($this->connection, CURLOPT_REFERER, $this->login_url); curl_setopt($this->connection, CURLOPT_URL, $this->upload_form_url); // set curl post vars curl_setopt($this->connection, CURLOPT_POST, 1); curl_setopt($this->connection, CURLOPT_POSTFIELDS, $this->postvarString()); // delete form vars which are not needed anymore $this->postvarDel('action_upload'); // execute curl $output = curl_exec($this->connection); // get the post url out of the output of curl $output_t = explode("var upload_url = \"", $output); $output_t = explode("\";", $output_t[1]); // write the form url $this->upload_post_url = $output_t[0]; return $output; } function upload($url) { if($this->upload_post_url != null) { // set dynamic form vars $this->postvarAdd('field_uploadfile', $url); // set static form vars $this->postvarAdd('&action_upload', 'Upload Video'); $this->postvarAdd('MAX_FILE_SIZE', '104857600'); // set curl options curl_setopt($this->connection, CURLOPT_REFERER, $this->upload_form_url); curl_setopt($this->connection, CURLOPT_URL, $this->upload_post_url); // set curl post vars curl_setopt($this->connection, CURLOPT_POST, 1); curl_setopt($this->connection, CURLOPT_POSTFIELDS, $this->postvarString()); // return an array with the curl output and the headers [return, info] return array("return" => curl_exec($this->connection), "info" => curl_getinfo($this->connection)); } else die("You need to make a new movie first!"); } // this function adds vars to the post array function postvarAdd($name, $value) { $this->post_vars[$name] = $value; } // this function deletes the asked vars in the post array function postvarDel() { foreach(func_get_args() as $argument) { unset($this->post_vars[$argument]); } } // this function converts the post array to an url string function postvarString() { $output = ""; foreach($this->post_vars as $key => $value) { $i++; if($i>1) $output .= "&"; $output .= "$key=$value"; } return $output; } // close the curl session function __destruct() { curl_close($this->connection); } } ?> [/code] And this is the code to execute the class (and format the output): [code] <?php $yt = new youtube(); $yt->login("username","password"); $yt->add("domino","A couple of domino blocks","domino, blocks"); echo "<pre>\n"; print_r($yt->upload('http://galleryish.com/test/youtube/domino.mov')); echo "\n</pre>\n"; ?>[/code] Thanks! Andreas Creten