我已登录用户。我找回了他最喜欢的视频。但是当我尝试上传视频时出现错误
Fatal error File to be uploaded at does not exist or is not readable.
这是我用来上传视频的代码
$myVideoEntry = new Zend_Gdata_YouTube_VideoEntry();
$file = '/files/trainingvideo1.mp4';
$file = realpath($file);
$filesource = $yt->newMediaFileSource($file);
$filesource->setContentType('video/mp4');
$filesource->setSlug($file);
$myVideoEntry->setMediaSource($filesource);
$myVideoEntry->setVideoTitle('Tutorial 1');
$myVideoEntry->setVideoDescription('Tutorial 1');
$myVideoEntry->setVideoCategory('Entertainment');
$myVideoEntry->SetVideoTags('testme');
$myVideoEntry->setVideoDeveloperTags(array('tester', 'test'));
$uploadUrl = 'http://uploads.gdata.youtube.com/feeds/api/users/default/uploads';
$newEntry = $yt->insertEntry($myVideoEntry, $uploadUrl, 'Zend_Gdata_YouTube_VideoEntry');
我感谢任何帮助。
答案 0 :(得分:1)
编辑:有了你的realpath()返回false的信息,我们可以假设您正在正确配置zend gdata并且只是传入一个错误的文件。
以下是关于realpath()的PHP文档:http://php.net/manual/en/function.realpath.php
重要的部分是:
realpath() returns FALSE on failure, e.g. if the file does not exist.
Note:
The running script must have executable permissions on all directories in the hierarchy, otherwise realpath() will return FALSE.
所以在这一点上我会继续:
祝你好运!
可以通过以下两种方式之一上传视频:通过直接上传视频或仅发送视频元数据并让用户通过HTML表单上传视频。
要直接上传视频,您必须先构建一个新的Zend_Gdata_YouTube_VideoEntry对象并指定一些必需的元数据。
下面的代码会创建一个空白»Zend_Gdata_YouTube_VideoEntry上传。然后使用»Zend_Gdata_App_MediaFileSource对象来保存实际的视频文件。在幕后,»Zend_Gdata_YouTube_Extension_MediaGroup对象用于保存所有视频的元数据。 $ uploadUrl是新条目发布到的位置。这可以使用当前经过身份验证的用户的$ userName指定,或者,您也可以使用字符串'default'来引用当前经过身份验证的用户。
$yt = new Zend_Gdata_YouTube($httpClient);
$myVideoEntry = new Zend_Gdata_YouTube_VideoEntry();
$filesource = $yt->newMediaFileSource('mytestmovie.mov');
$filesource->setContentType('video/quicktime');
$filesource->setSlug('mytestmovie.mov');
$myVideoEntry->setMediaSource($filesource);
$myVideoEntry->setVideoTitle('My Test Movie');
$myVideoEntry->setVideoDescription('My Test Movie');
// Note that category must be a valid YouTube category !
$myVideoEntry->setVideoCategory('Comedy');
// Set keywords, note that this must be a comma separated string
// and that each keyword cannot contain whitespace
$myVideoEntry->SetVideoTags('cars, funny');
// Optionally set some developer tags
$myVideoEntry->setVideoDeveloperTags(array('mydevelopertag',
'anotherdevelopertag'));
// Optionally set the video's location
$yt->registerPackage('Zend_Gdata_Geo');
$yt->registerPackage('Zend_Gdata_Geo_Extension');
$where = $yt->newGeoRssWhere();
$position = $yt->newGmlPos('37.0 -122.0');
$where->point = $yt->newGmlPoint($position);
$myVideoEntry->setWhere($where);
// Upload URI for the currently authenticated user
$uploadUrl =
'http://uploads.gdata.youtube.com/feeds/users/default/uploads';
// Try to upload the video, catching a Zend_Gdata_App_HttpException
// if available or just a regular Zend_Gdata_App_Exception
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();
}
要将视频上传为私有,只需使用:$ myVideoEntry-> setVideoPrivate();在执行上传之前。 $ videoEntry-> isVideoPrivate()可用于检查视频条目是否为私有。
来源:http://framework.zend.com/manual/en/zend.gdata.youtube.html