编辑:根据您的 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.
所以在这一点上,我会继续:
- 检查文件是否存在以及您的 URL 是否正确 - 可能首先尝试使用绝对 URL 来测试并逐步建立相对 URL
- 检查文件的权限,确保它可以被所有人执行(我认为是 755 unix 权限)
祝你好运!
Zend Gdata Youtube 文档:
可以通过以下两种方式之一上传视频:直接上传视频或仅发送视频元数据并让用户通过 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