Hi all, im trying to get SWFUpload to work with the new YouTube API.
I am using the following code to upload a video directly to youtube from SWFUpload:
upload.php
$yt = new Zend_Gdata_YouTube($httpClient);
$upload_name = "Filedata";
$filesource->setContentType('video/mp4');
// set slug header
$filesource->setSlug($upload_name);
// add the filesource to the video entry
$myVideoEntry->setMediaSource($filesource);
// create a new Zend_Gdata_YouTube_MediaGroup object
$mediaGroup = $yt->newMediaGroup();
$mediaGroup->title = $yt->newMediaTitle()->setText('My Test Movie');
$mediaGroup->description = $yt->newMediaDescription()->setText('My description');
// the category must be a valid YouTube category
// optionally set some developer tags (see Searching by Developer Tags for more details)
$mediaGroup->category = array(
$yt->newMediaCategory()->setText('Autos')->setScheme('http://gdata.youtube.com/schemas/2007/categories.cat'),
$yt->newMediaCategory()->setText('mydevelopertag')->setScheme('http://gdata.youtube.com/schemas/2007/developertags.cat'),
$yt->newMediaCategory()->setText('anotherdevelopertag')->setScheme('http://gdata.youtube.com/schemas/2007/developertags.cat')
);
// set keywords
$mediaGroup->keywords = $service->newMediaKeywords()->setText('cars, funny');
$myVideoEntry->mediaGroup = $mediaGroup;
// set video 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);
$entry->setWhere($where);
// upload URL for the currently authenticated user
$uploadUrl = 'http://uploads.gdata.youtube.com/feeds/users/default/uploads';
try {
$newEntry = $yt->insertEntry($myVideoEntry, $uploadUrl, 'Zend_Gdata_YouTube_VideoEntry');
} catch (Zend_Gdata_App_Exception $e) {
echo $e->getMessage();
}
By setting the $upload_name string to "Filedata" i was hoping that the selected files from SWFUpload would be recognised by the code and send the file but it doesnt seem to upload.
any ideas or has anybody experimented with this before?
Thanks.
April 2, 2008 - 1:08pm
"Filedata" is just a string. It is the Post name for the file's data. In PHP it becomes the Key to the file upload object held in the $_FILES array which tells you the name, status, and physical location of the uploaded file.
You need to use $_FILES["Filedata"] to get at the uploaded file and send whatever information you need to.
It looks like to me setSlug wants the file's name not the string "Filedata".
I know it's only a snippet but seem to be missing the part where you tell your $filesource where the file is:
$filesource = $yt->newMediaFileSource('mytestmovie.mov');
Where 'mytestmovie.mov' is something like $_FILES["Filedata"]['tmp_name']