Skip to content

Instantly share code, notes, and snippets.

@phpfunk
Forked from kyleslattery/direct upload.php
Created July 20, 2012 12:10
Show Gist options
  • Save phpfunk/3150388 to your computer and use it in GitHub Desktop.
Save phpfunk/3150388 to your computer and use it in GitHub Desktop.
<?php
include('phpviddler.php');
$user = 'YOUR USERNAME';
$pass = 'YOUR PASSWORD';
$api_key = 'YOUR API KEY';
$callback_url = 'CALLBACK';
$v = new Viddler_V2($api_key);
// Get a sessionid
$auth = $v->viddler_users_auth(array('user' => $user, 'password' => $pass));
$sessionid = $auth['auth']['sessionid'];
// Call prepareUpload to retrieve the token and endpoint we need to use
$prepare_resp = $v->viddler_videos_prepareUpload(array('sessionid' => $sessionid));
// If you wish to permit a current video to be replaced you can call prepareUpload like this:
// $prepare_resp = $v->viddler_videos_prepareUpload(array('sessionid' => $sessionid, 'allow_replace'=>true));
$upload_server = $prepare_resp['upload']['endpoint'];
$upload_token = $prepare_resp['upload']['token'];
/**
HTML field below is to support replacing of a current video.
If you want to upload a video to replace an already existing video,
simply add a hidden input with the name of 'video_id' and a value
of the video_id to replace.
IE: <input type="hidden" name="video_id" value="VIDEO_ID_TO_REPLACE (OPTIONAL)" />
**/
?>
<form method="post" action="<?= $upload_server ?>" enctype="multipart/form-data">
<input type="hidden" name="uploadtoken" value="<?= $upload_token ?>" />
<input type="hidden" name="callback" value="<?= $callback_url ?>" />
<label>Title:</label> <input type="text" name="title" /><br />
<label>Description:</label> <input type="text" name="description" /><br />
<label>Tags:</label> <input type="text" name="tags" /><br />
<label>File:</label> <input type="file" name="file" /><br />
<input type="submit" value="Upload" />
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment