VP Factory API example code (upload button)

138 views
Skip to first unread message

VP Factory

unread,
Nov 4, 2010, 4:30:39 PM11/4/10
to VP Factory API
At the core of every video sharing website (such as Youtube, Vimeo
and
others) stands the functionality which enables users to upload their
own videos. An easy way to let the users upload their video content
is
to provide an upload button.

What does it do?
It lets you browse for a video on your computer and then uploads the
video into a test account. After the processing is over, the video
will appear in the player.

Below you can find the required PHP code.
<?php
require_once('../misc/api/apivpf.class.php');
$key = '4297f44b13955235245b2497399d7a93';
$api = new ApiVPF($key);
$upload_url = $api->baseURL() . 'addhostedvideo';
$player_txtid = '69421f032498c97020180038fddb8e24';
if (isset($_FILES['Filedata'])) {
$file = $_FILES['Filedata']['tmp_name'];
$data = array(
'Filedata'=>"@$file",
'key'=>$_REQUEST['key']
);
$ch = curl_init($upload_url);
curl_setopt($ch, CURLOPT_POST ,1);
curl_setopt($ch, CURLOPT_POSTFIELDS , $data);
curl_setopt($ch, CURLOPT_HEADER ,0); // DO NOT RETURN
HTTP
HEADERS
curl_setopt($ch, CURLOPT_RETURNTRANSFER ,1); // RETURN THE
CONTENTS
OF THE CALL
$xml_video = curl_exec($ch);
$myVideo = simplexml_load_string($xml_video);
$video_mdid = $myVideo->mdid;
header("Location: {$api->serverURL()}apidemo/upload.php?
referralVideo={$video_mdid}");
}

?>
Note:
We use cURL to send our data to the API server for processing and
expect a XML response which describes our newly uploaded video.
We then use this response in order to reload the player with the
uploaded content.
The HTML form necessary for the upload is described below:
<form id="file_form" enctype="multipart/form-data" action=""
method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="10485760" />
<input type="hidden" name="key" value="<?php echo $api-
>getKey(); ?>"/

Choose a file to upload: <input name="Filedata" type="file" /
><br />
<input type="submit" value="Upload File" />
</form>
Reply all
Reply to author
Forward
0 new messages