PhpRiot
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Browser-based upload

Browser-based uploading is performed almost identically to direct uploading, except that you do not attach a Zend_Gdata_App_MediaFileSource object to the Zend_Gdata_YouTube_VideoEntry you are constructing. Instead you simply submit all of your video's meta-data to receive back a token element which can be used to construct an HTML upload form.

Example 470. Browser-based upload

<?php
$yt 
= new Zend_Gdata_YouTube($httpClient);

$myVideoEntry= new Zend_Gdata_YouTube_VideoEntry();
$myVideoEntry->setVideoTitle('My Test Movie');
$myVideoEntry->setVideoDescription('My Test Movie');

// Note that category must be a valid YouTube category
$myVideoEntry->setVideoCategory('Comedy');
$myVideoEntry->SetVideoTags('cars, funny');

$tokenHandlerUrl 'http://gdata.youtube.com/action/GetUploadToken';
$tokenArray $yt->getFormUploadToken($myVideoEntry$tokenHandlerUrl);
$tokenValue $tokenArray['token'];
$postUrl $tokenArray['url'];

The above code prints out a link and a token that is used to construct an HTML form to display in the user's browser. A simple example form is shown below with $tokenValue representing the content of the returned token element, as shown being retrieved from $myVideoEntry above. In order for the user to be redirected to your website after submitting the form, make sure to append a $nextUrl parameter to the $postUrl above, which functions in the same way as the $next parameter of an AuthSub link. The only difference is that here, instead of a single-use token, a status and an id variable are returned in the URL.

Example 471. Browser-based upload: Creating the HTML form

<?php
// place to redirect user after upload
$nextUrl 'http://mysite.com/youtube_uploads';

$form '<form action="'$postUrl .'?nexturl='$nextUrl .
        
'" method="post" enctype="multipart/form-data">'.
        
'<input name="file" type="file"/>'.
        
'<input name="token" type="hidden" value="'$tokenValue .'"/>'.
        
'<input value="Upload Video File" type="submit" />'.
        
'</form>';

Zend Framework