public function upload() { $viddler = new Viddler_V2($this->api_key); if (isset($this->userName) && isset($this->password)) { $user = $viddler->viddler_users_auth(array('user' => $this->userName, 'password' => $this->password)); $params = array('sessionid' => $user['auth']['sessionid'], 'title' => $this->getWebTitle(), 'tags' => $this->getWebKeywords(), 'description' => $this->getWebDescription(), 'file' => '@' . $this->video->path); $prepare = $viddler->viddler_videos_prepareUpload(array('sessionid' => $user['auth']['sessionid'])); $response = $viddler->viddler_videos_upload($params, $prepare['upload']['endpoint']); //print_r ( $response ); if (is_array($response)) { $videoArray = $response['video']; if (is_array($videoArray)) { $this->uploadLocation = $videoArray['url']; } } } else { $response = "No username or password to use for uploading"; } return $response; }
If session id is empty, something went wrong. You probably want to handle the error better, but this is for example purposes only. **/ if (empty($session_id)) { print '<pre>'; print_r($auth); print '</pre>'; exit; } /** 1. Call prepareUpload 2. Get endpoint 3. Get token **/ $response = $v->viddler_videos_prepareUpload(array('sessionid' => $session_id)); $endpoint = isset($response['upload']['endpoint']) ? $response['upload']['endpoint'] : NULL; $token = isset($response['upload']['token']) ? $response['upload']['token'] : NULL; /** Check for endpoint and token. As in above, you will want to handle this error better. **/ if (empty($endpoint) || empty($token)) { print '<pre>'; print_r($response); print '</pre>'; exit; } /** Set your direct upload form variables.
public function actionGetVideoDetails() { $vidler = Yii::app()->getComponents(false); $user = $vidler['vidler']['user']; $pass = $vidler['vidler']['pwd']; $api_key = $vidler['vidler']['appkey']; $v = new Viddler_V2($api_key); $auth = $v->viddler_users_auth(array('user' => $user, 'password' => $pass)); $sessionid = $auth['auth']['sessionid']; $callback_url = 'http://' . $_SERVER['HTTP_HOST'] . '' . $_SERVER['SCRIPT_NAME'] . '/finao/GetUpdatedvideo/uploadid/' . $_POST['uploadedid'] . '/upload/Video/finaoid/' . $_POST['finaoid'] . ''; $prepare_resp = $v->viddler_videos_prepareUpload(array('sessionid' => $sessionid)); $upload_server = $prepare_resp['upload']['endpoint']; $upload_token = $prepare_resp['upload']['token']; //$this->updateviddlerstatus($sessionid,$uploadedimages,$v); $this->renderPartial('_updatefinaovideo', array('callback_url' => $callback_url, 'upload_server' => $upload_server, 'upload_token' => $upload_token, 'uploadedid' => $_POST['uploadedid'], 'finaoid' => $_POST['finaoid'])); }
<?php require_once './config.php'; require_once '../../src/lib/phpviddler/phpviddler.php'; $v = new Viddler_V2(VIDDLER_API_KEY); $auth = $v->viddler_users_auth(array('user' => VIDDLER_USERNAME, 'password' => VIDDLER_PASSWORD)); if ($_GET['action'] == 'prepareUpload') { $params = array('sessionid' => $auth['auth']['sessionid']); if (VIDDLER_ALLOW_VIDEO_REPLACE) { $params['allow_replace'] = true; } $response = $v->viddler_videos_prepareUpload($params); header('Content-Type: application/json'); //Bacause PHP library uses php responses $response['upload']['endpoint'] = str_replace('.php', '.json', $response['upload']['endpoint']); echo json_encode($response); }
public function actionGetadminvideo() { $userid = $_POST['userid']; $groupid = $_POST['groupid']; $vidler = Yii::app()->getComponents(false); $user = $vidler['vidler']['user']; $pass = $vidler['vidler']['pwd']; $api_key = $vidler['vidler']['appkey']; $v = new Viddler_V2($api_key); $auth = $v->viddler_users_auth(array('user' => $user, 'password' => $pass)); $sessionid = $auth['auth']['sessionid']; $prepare_resp = $v->viddler_videos_prepareUpload(array('sessionid' => $sessionid)); $upload_server = $prepare_resp['upload']['endpoint']; $upload_token = $prepare_resp['upload']['token']; $callback_url = 'http://' . $_SERVER['HTTP_HOST'] . '' . $_SERVER['SCRIPT_NAME'] . '/finao/GetadminVideodetail/groupid/' . $groupid; $this->renderPartial('_adminvideo', array('userid' => $userid, 'groupid' => $groupid, 'callback_url' => $callback_url, 'upload_server' => $upload_server, 'upload_token' => $upload_token)); }
<?php // You can run this on your server or via command line. include '../phpviddler.php'; $api_key = ''; $user = ''; $password = ''; $file = ''; $viddler = new Viddler_V2($api_key); $user = $viddler->viddler_users_auth(array('user' => $user, 'password' => $password)); $params = array('sessionid' => $user['auth']['sessionid'], 'title' => 'test20101215', 'tags' => 'tag1,tag2,tag3', 'description' => 'desc here', 'file' => '@' . $file); $prepare = $viddler->viddler_videos_prepareUpload(array('sessionid' => $user['auth']['sessionid'])); $results = $viddler->viddler_videos_upload($params, $prepare['upload']['endpoint']); print_r($results); echo "\n";
function uploaddata($type, $sourcetype, $finaoid, $userid, $uploadtext, $data, $captiondata) { $target_path = $globalpath . "images/uploads/finaoimages/"; $target_thumb = $globalpath . "images/uploads/finaoimages/thumb/"; $target_medium = $globalpath . "images/uploads/finaoimages/medium/"; $upload_path = "/images/uploads/finaoimages"; $query = "insert into fn_uploaddetails (`uploadtype`,`upload_text`,`upload_sourcetype`, `upload_sourceid`, `uploadedby`, `uploadeddate`, `status`) values ('{$type}','{$uploadtext}','{$sourcetype}','{$finaoid}','{$userid}',now(),1)"; mysql_query($query); $uploadid = mysql_insert_id(); if (!empty($data)) { if ($data['image1']['name'] != '') { $sno = 0; foreach ($data as $key => $val) { $name = $val['name']; $uploadfile_name = $finaoid . "-" . $name; $tmpname = $val['tmp_name']; $target_main = $target_path . $uploadfile_name; $target_thumb = $target_thumb . $uploadfile_name; $target_medium = $target_medium . $uploadfile_name; @move_uploaded_file($tmpname, $target_main); $resize = new ResizeImage($target_main); $resize->resizeTo(100, 100, 'default'); $resize->saveImage($target_thumb); $resize_m = new ResizeImage($target_main); $resize_m->resizeTo(240, 240, 'default'); $resize_m->saveImage($target_medium); $query = "insert into fn_images (`upload_id`,`uploadfile_name`,`uploadfile_path`, `caption`, `uploadedby`, `uploadeddate`, `status`) values ('{$uploadid}','{$uploadfile_name}','{$upload_path}','{$captiondata[$sno]}','{$userid}',now(),1)"; mysql_query($query); $sno++; } } else { $target_path = $target_path . $finaoid . "-" . basename($data['video']['name']); @move_uploaded_file($data['video']['tmp_name'], $target_path); set_time_limit(0); include 'phpviddler.php'; $v = new Viddler_V2('145i86zgnzi1h1xln0ly'); $auth = $v->viddler_users_auth(array('user' => ' finaonation', 'password' => 'Finao123')); $session_id = isset($auth['auth']['sessionid']) ? $auth['auth']['sessionid'] : NULL; $response = $v->viddler_videos_prepareUpload(array('sessionid' => $session_id)); $endpoint = isset($response['upload']['endpoint']) ? $response['upload']['endpoint'] : NULL; $token = isset($response['upload']['token']) ? $response['upload']['token'] : NULL; $query = array('uploadtoken' => $token, 'title' => 'Video from iphone App', 'description' => 'Video from iphone App', 'tags' => 'testing,upload', 'file' => '@../../preprod/images/uploads/finaoimages/' . $finaoid . "-" . basename($data['video']['name'])); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $endpoint); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); curl_setopt($ch, CURLOPT_HEADER, TRUE); curl_setopt($ch, CURLOPT_NOBODY, FALSE); curl_setopt($ch, CURLOPT_TIMEOUT, 0); curl_setopt($ch, CURLOPT_POST, TRUE); curl_setopt($ch, CURLOPT_POSTFIELDS, $query); $response = curl_exec($ch); $info = curl_getinfo($ch); $header_size = $info['header_size']; $header = substr($response, 0, $header_size); $video = unserialize(substr($response, $header_size)); curl_close($ch); @unlink('../../preprod/images/uploads/finaoimages/' . $finaoid . "-" . basename($data['video']['name'])); $videoid = $video['video']['id']; $results = $v->viddler_videos_getDetails(array('sessionid' => $session_id, 'video_id' => $videoid)); $videostatus = $results['video']['status']; $video_img = $results['video']['thumbnail_url']; $query = "insert into fn_videos (`upload_id`,`videoid`,`videostatus`, `video_img`, `caption`, `uploadedby`, `uploadeddate`, `status`) values ('{$uploadid}','{$videoid}','{$videostatus}','{$video_img}','{$captiondata['0']}','{$userid}',now(),1)"; mysql_query($query); } } // updating the current date time in fn_user_finao $sqlUpdate = "update fn_user_finao set updateddate=NOW(),updatedby=" . $userid . " where user_finao_id=" . $finaoid; mysql_query($sqlUpdate); // end of fn_user_finao update }