我正在使用以下代码在 youtube 上上传大小视频。该代码在本地主机上正常工作,但是当我在服务器上运行它并上传相同的视频时,它会上传所有小文件,但不会上传大文件。上传完成后,youtube 显示以下大文件错误:失败(无法转换视频文件)
<?php
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata_YouTube');
Zend_Loader::loadClass('Zend_Gdata_AuthSub');
Zend_Loader::loadClass('Zend_Gdata_App_Exception');
session_start();
$_SESSION['Key'] = 'My Developer Key';
?>
<html>
<head>
</head>
<body>
<?php
if (!isset($_SESSION['sessionToken']) && !isset($_GET['token']) ){
echo '<a href="' . getAuthSubRequestUrl() . '">Login!</a>';
} else if (!isset($_SESSION['sessionToken']) && isset($_GET['token'])) {
$_SESSION['sessionToken'] = Zend_Gdata_AuthSub::getAuthSubSessionToken($_GET['token']);
}
if(isset($_SESSION['sessionToken']))
{
$yt = new Zend_Gdata_YouTube(getAuthSubHttpClient());
$myVideoEntry = new Zend_Gdata_YouTube_VideoEntry();
$filesource = $yt->newMediaFileSource('myvideo.mov');
$filesource->setContentType('video/quicktime');
$filesource->setSlug('myvideo.mov');
$myVideoEntry->setMediaSource($filesource);
$myVideoEntry->setVideoDescription('this is my test video');
$myVideoEntry->setVideoCategory("Music");
$myVideoEntry->setVideoTitle('this is videoo');
$myVideoEntry->SetVideoTags('tag1');
$uploadUrl ='http://uploads.gdata.youtube.com/feeds/users/default/uploads';
try {
$newEntry = $yt->insertEntry($myVideoEntry,
$uploadUrl,
'Zend_Gdata_YouTube_VideoEntry');
} catch (Zend_Gdata_App_HttpException $httpException) {
echo $httpException->getRawResponseBody();
} catch (Zend_Gdata_App_Exception $e) {
echo $e->getMessage();
}
}
?>
</body>
</html>
<?php
function getAuthSubRequestUrl()
{
$next = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
$scope = 'http://gdata.youtube.com';
$secure = false;
$session = true;
return Zend_Gdata_AuthSub::getAuthSubTokenUri($next, $scope, $secure, $session);
}
function getAuthSubHttpClient()
{
if (!isset($_SESSION['sessionToken']) && !isset($_GET['token']) ){
echo '<a href="' . getAuthSubRequestUrl() . '">Login!</a>';
return;
} else if (!isset($_SESSION['sessionToken']) && isset($_GET['token'])) {
$_SESSION['sessionToken'] = Zend_Gdata_AuthSub::getAuthSubSessionToken($_GET['token']);
}
$httpClient = Zend_Gdata_AuthSub::getHttpClient($_SESSION['sessionToken']);
$httpClient->setHeaders('X-GData-Key', 'key='. $_SESSION['Key']);
return $httpClient;
}
function updateAuthSubToken($singleUseToken)
{
try {
$sessionToken = Zend_Gdata_AuthSub::getAuthSubSessionToken($singleUseToken);
} catch (Zend_Gdata_App_Exception $e) {
print 'ERROR - Token upgrade for ' . $singleUseToken
. ' failed : ' . $e->getMessage();
return;
}
$_SESSION['sessionToken'] = $sessionToken;
generateUrlInformation();
header('Location: ' . $_SESSION['homeUrl']);
}
?>