PHP - How To Detect An Upload From Youtube?
Basically what the title says, I want to detect a upload and post a notification, how would i do this?
Similar TutorialsHas anyone had any success doing this? I'm not sure if I should try to write this myself or use some kind of framework. I found the Zend Gdata framework (http://framework.zend.com/manual/en/zend.gdata.html) and tried it out but I kept getting error: Warning: include_once() [function.include]: Failed opening '1' for inclusion (include_path='.:/usr/share/pear') I'm assuming it needs to find PEAR which I don't have installed but no where in the Zend docs does it say that it requires PEAR so I'm a little confused. I've never used any of the Zend frameworks so I have no idea if it needs PEAR or not. Anyone have any other methods for doing this? thanks. hello guys i am a newbie want help with how to upload a youtube in your script and in database i know about the $_files thing but how do i give a link please help me out !! How could I from the varying URLs parse only the YouTube video ID? http://www.youtube.com/watch?v=SwrawcORlp0&feature=player_embedded http://www.youtube.com/watch?v=SwrawcORlp0&feature=popular How can I from the URLs above only extract the id into a variable $url SwrawcORlp0 Thanks, df I have code written for image uploading, but it doesn't allow multiple images on a single upload, and doesn't re-size. Anyone willing to share a good upload script that will do the following?: -Allow multiple image uploads (10+ per submission), -Re-size images on upload, and -Rename images. Thanks Brett Hi everyone, I have a page that i use to upload images to my website, i got a bit fed up of uploading one at a time so i decided to add multiple file fields to the form to upload multiple images at the same time. Im having a few problems, iv read up he http://www.php.net/manual/en/features.file-upload.multiple.php and it seems all i have to do is add [] to the form names to turn them into arrays. However when i come to upload the images, i keep getting the "$error[] = "Incorrect format!...." error from the code below. I cant seem to figure out what the problem is. Could anybody please point me in the right direction? <?php session_start(); $id = $_SESSION['id']; $connect = mysql_connect("localhost","leemp5_admin","p7031521"); mysql_select_db("leemp5_database"); $query = mysql_query("SELECT * FROM users WHERE id='$id'"); $row = mysql_fetch_assoc($query); $username = $row['username']; $submit = $_POST['submit']; $type = $_FILES['image']['type']; $size = $_FILES['image']['size']; $max_size = "1000"; $width = "100"; $height = "100"; $error = array(); function make_thumb($image_name,$filename,$new_width,$new_height) { $ext=getExtension($image_name); if(!strcmp("jpg",$ext) || !strcmp("jpeg",$ext)) $source_image=imagecreatefromjpeg($image_name); if(!strcmp("png",$ext)) $source_image=imagecreatefrompng($image_name); if(!strcmp("gif",$ext)) $source_image=imagecreatefromgif($image_name); $old_x=imageSX($source_image); $old_y=imageSY($source_image); $ratio1=$old_x/$new_width; $ratio2=$old_y/$new_height; if($ratio1>$ratio2) { $thumb_width=$new_width; $thumb_height=$old_y/$ratio1; } else { $thumb_height=$new_height; $thumb_width=$old_x/$ratio2; } $destination_image=ImageCreateTrueColor($thumb_width,$thumb_height); imagecopyresampled($destination_image,$source_image,0,0,0,0,$thumb_width,$thumb_height,$old_x,$old_y); if(!strcmp("jpg",$ext) || !strcmp("jpeg",$ext)) { imagejpeg($destination_image,$filename); } if(!strcmp("png",$ext)) { imagepng($destination_image,$filename); } if(!strcmp("gif",$ext)) { imagegif($destination_image,$filename); } imagedestroy($destination_image); imagedestroy($source_image); } function getExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } if($submit) { $image=$_FILES['image']['name']; if ($image) { $filename = stripslashes($_FILES['image']['name']); $extension = getExtension($filename); $extension = strtolower($extension); if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) { $error[] = "Incorrect format! Please make sure your image is a .jpg, .jpeg, .png or .gif file."; } else { $size=getimagesize($_FILES['image']['tmp_name']); $sizekb=filesize($_FILES['image']['tmp_name']); if ($sizekb > $max_size*1024) { $error[] = "Your image is too big! The maximum upload size is 1MB."; } else { $image_name=time().'.'.$extension; $newname="uploads/" . $username . "/images/".$image_name; $copied = copy($_FILES['image']['tmp_name'], $newname); if (!$copied) { $error[] = "There was an error uploading your image. Please try again!"; } else { $thumb_name='uploads/' . $username . '/images/thumbs/thumb_'.$image_name; $thumb=make_thumb($newname,$thumb_name,$width,$height); } } } } else { $error[] = "Please select an image to upload!"; } if(empty($error)) { echo "Upload Successfully!<br />"; echo '<img src="'.$thumb_name.'">'; mysql_query("INSERT INTO images VALUES ('','$username','$image_name','','','','','uploads/$username/images/$image_name','uploads/$username/images/thumbs/thumb_$image_name','$type','$size')"); } else { echo implode($error); } } ?> <form method="post" enctype="multipart/form-data" action="upload_images.php"> <input type="file" name="image[]" /><br /> <input type="file" name="image[]" /><br /> <input type="file" name="image[]" /><br /> <input type="file" name="image[]" /><br /> <input type="file" name="image[]" /><br /> <input type="file" name="image[]" /><br /> <input type="submit" name="submit" value="Upload"> </form> Thanks hello, I am trying to figure out how I can take only the v= in the youtube urls http://www.youtube.com/watch?v=nGawAhRjtoA&feature=topvideos i just want php to take v=nGawAhRjtoA and ignore everything else any ideas guys/gals? thanks The application that I want to build is quite simple. Here is a bit of the background of the work flow: In my company, we create video for our client profile. After the video is done, we upload the video to our website and to youtube. It is done automatically. After a period of time, the client can delete the video. Of course, it will delete the video in our system as well as the video in youtube. For now, the video in our system is deleted automatically. However, youtube video is deleted manually. Our company has grown to have quite a lot of clients. It's hard for us to keep track clients that requested to delete their videos. We want to be able to have an application that will delete youtube video automatically. I already tried to play around with youtube authentication in http://code.google.com/apis/youtube/2.0/developers_guide_php.html#Authentication but I have no luck with the authentication. I want the application to be able to delete the video under my youtube account without having me to login to youtube. In my case right now, every time the application wants to delete the video, I have to send the request to youtube and ask for verification (i.e. I have to do application verification every time). Here is what I have done so far: ini_set('display_errors', 1); ini_set('log_errors', 1); ini_set('error_log', dirname(__FILE__) . '/error_log.txt'); error_reporting(E_ALL); require_once('db_class.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(); setLogging('on'); $_SESSION['developerKey'] = 'AI39si5H3hL9tcKOMl80IqzoC6nb87ka1QLgHxLp9nFi1l44dLa987_Gi0rbofLePQdFEWf1lrSB8KGs4lXIrcF8TR6PhUcO3Q'; function getAuthSubRequestUrl() { $next = 'http://example.com/youtube_delete_video.php'; $scope = 'http://gdata.youtube.com'; $secure = false; $session = true; return Zend_Gdata_AuthSub::getAuthSubTokenUri($next, $scope, $secure, $session); } 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']); } function getAuthSubHttpClient() { try { $httpClient = Zend_Gdata_AuthSub::getHttpClient($_SESSION['sessionToken']); } catch (Zend_Gdata_App_Exception $e) { print 'ERROR - Could not obtain authenticated Http client object. ' . $e->getMessage(); return; } $httpClient->setHeaders('X-GData-Key', 'key='. $_SESSION['developerKey']); return $httpClient; } function generateUrlInformation() { if (!isset($_SESSION['operationsUrl']) || !isset($_SESSION['homeUrl'])) { $_SESSION['operationsUrl'] = 'http://'. $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']; $path = explode('/', $_SERVER['PHP_SELF']); $path[count($path)-1] = 'index.php'; $_SESSION['homeUrl'] = 'http://'. $_SERVER['HTTP_HOST'] . implode('/', $path); } } function loggingEnabled() { if ($_SESSION['logging'] == 'on') { return true; } } function setLogging($loggingOption, $maxLogItems = 10) { switch ($loggingOption) { case 'on' : $_SESSION['logging'] = 'on'; $_SESSION['log_currentCounter'] = 0; $_SESSION['log_maxLogEntries'] = $maxLogItems; break; case 'off': $_SESSION['logging'] = 'off'; break; } } function logMessage($message, $messageType) { if (!isset($_SESSION['log_maxLogEntries'])) { $_SESSION['log_maxLogEntries'] = 20; } if (!isset($_SESSION['log_currentCounter'])) { $_SESSION['log_currentCounter'] = 0; } $currentCounter = $_SESSION['log_currentCounter']; $currentCounter++; if ($currentCounter > $_SESSION['log_maxLogEntries']) { $_SESSION['log_currentCounter'] = 0; } $logLocation = 'log_entry_'. $currentCounter . '_' . $messageType; $_SESSION[$logLocation] = $message; $_SESSION['log_currentCounter'] = $currentCounter; } function printCacheWarning() { return '<p class="note">' . 'Please note that the change may not be reflected in the API ' . 'immediately due to caching.<br/>' . 'Please refer to the API documentation for more details.</p>'; } function editVideoData($videoId) { $httpClient = getAuthSubHttpClient(); $youTubeService = new Zend_Gdata_YouTube($httpClient); $videoEntryToUpdate = $youTubeService->getFullVideoEntry($videoId); if (!$videoEntryToUpdate instanceof Zend_Gdata_YouTube_VideoEntry) { print 'ERROR - Could not find a video entry with id ' . $videoId . '<br />' . printCacheWarning(); return; } try { $putUrl = $videoEntryToUpdate->getEditLink()->getHref(); } catch (Zend_Gdata_App_Exception $e) { print 'ERROR - Could not obtain video entry\'s edit link: ' . $e->getMessage() . '<br />'; return; } $videoEntryToUpdate->setVideoTitle("My Test Movie - Private 10000012"); $videoEntryToUpdate->setVideoDescription("My Test Movie - Private 10000012"); $videoEntryToUpdate->setVideoPrivate(); try { $updatedEntry = $youTubeService->updateEntry($videoEntryToUpdate, $putUrl); if (loggingEnabled()) { logMessage($httpClient->getLastRequest(), 'request'); logMessage($httpClient->getLastResponse()->getBody(), 'response'); } } catch (Zend_Gdata_App_HttpException $httpException) { print 'ERROR ' . $httpException->getMessage() . ' HTTP details<br /><textarea cols="100" rows="20">' . $httpException->getRawResponseBody() . '</textarea><br />' . '<a href="session_details.php">' . 'click here to view details of last request</a><br />'; return; } catch (Zend_Gdata_App_Exception $e) { print 'ERROR - Could not post video meta-data: ' . $e->getMessage(); return; } print 'Entry updated successfully.<br /><a href="#" onclick="' . 'ytVideoApp.presentFeed(\'search_owner\', 5, 0, \'none\'); ' . 'ytVideoApp.refreshSearchResults();" >' . '(refresh your video listing)</a><br />' . printCacheWarning(); } if (!isset($_GET['token'])) { $returnURL = getAuthSubRequestUrl(); echo "<a href=".$returnURL.">Link To Google</a>"; } else { $singleUseToken = $_GET['token']; updateAuthSubToken($singleUseToken); /* editVideoData('mJDRXXaFVGw'); */ } This is how I call the function: http://example.com/youtube_delete_video.php So, what I need basically is to know 1. how can I store the authentication after I verify it from youtube? 2. What function to populate after I store the authentication? <- I couldn't figure where this part is in the documentation. PS: example.com is not a real url. It's just for the sake of writing the post he ) Hi, I'm working with the YouTube API to echo a feed based on a user's query. My current code is below. With this code, a whole list of videos is retrieved. However, in order to present the feed as I wish to... I need to return each video in the feed individually. I am unsure how to do this and any advice would be really appreciated. Code: [Select] $feedURL = "http://gdata.youtube.com/feeds/api/videos/-/$youtubeQuery?orderby=viewCount&max-results=10"; // read feed into SimpleXML object $sxml = simplexml_load_file($feedURL); // iterate over entries in resultset // print each entry's details foreach ($sxml->entry as $entry) { // get nodes in media: namespace for media information $media = $entry->children('http://search.yahoo.com/mrss/'); // get video player URL $attrs = $media->group->player->attributes(); $watch = $attrs['url']; // get video thumbnail $attrs = $media->group->thumbnail[0]->attributes(); $thumbnail = $attrs['url']; // get <yt:duration> node for video length $yt = $media->children('http://gdata.youtube.com/schemas/2007'); $attrs = $yt->duration->attributes(); $length = $attrs['seconds']; // get video title $title = $media->group->title; // get <gd:rating> node for video ratings $gd = $entry->children('http://schemas.google.com/g/2005'); if ($gd->rating) { $attrs = $gd->rating->attributes(); $rating = $attrs['average']; } else { $rating = 0; } } ?> Youtube has an advanced api to deliver xml; but when I try to parse its xml, it is not well-defined. I want to get "average rating" for a given video, but simple xml load disregard this section: $xml = simplexml_load_file('http://gdata.youtube.com/feeds/mobile/videos/wZ252E282go'); print_r($xml); How can I put the value of "average rating" into an string to echo? Before you say about trying to use curl and fsockopen...I have tried those already but my host does not allow it due to their settings on their php.ini file. I am wondering if there is a way (other than those above) to grab the latest videos from a specific user on youtube, and be able to display them on a website, such as grabbing information about the video, as well as displaying it. If this is at all possible, and you can help...thanks in advance. Code: [Select] $txt = preg_replace( "#\[yt\]http://www.youtube.com/watch?v=(.+?)\[/yt\]#is", '<embed src="http://www.youtube.com/v/\\1" type="application/x-shockwave-flash" wmode="transparent" width="512" height="313" allowfullscreen="true" />', $txt ); Okay this is my code just for inserting it into HTML, the problem is whenever I try to use: Code: [Select] [yt]http://www.youtube.com/watch?v=l1G7TJD6Xu0[/yt] On my form to enter it does not work? But if I use Code: [Select] $txt = preg_replace( "#\[yt\](.+?)\[/yt\]#is", '<embed src="http://www.youtube.com/v/\\1" type="application/x-shockwave-flash" wmode="transparent" width="512" height="313" allowfullscreen="true" />', $txt ); Code: [Select] [yt]l1G7TJD6Xu0[/yt] It works. But I want to use the full URL of the youtube, so I don't want my users to copy/paste just the "l1G7TJD6Xu0" Code , any help? Thank you I have this function: function bbcode($input){ $input = strip_tags($input); $input = htmlentities($input); $search = array( '/\[b\](.*?)\[\/b\]/is', '/\[i\](.*?)\[\/i\]/is', '/\[u\](.*?)\[\/u\]/is', '/\[img\](.*?)\[\/img\]/is', '/\[url=http://(.*?)\](.*?)\[\/url\]/is', '/\[color=(.*?)\](.*?)\[\/color\]/is', '/\[yt\](.*?)\[\/yt\]/is', ); $replace = array( '<b>$1</b>', '<i>$1</i>', '<u>$1</u>', '<img src="$1" style="border:0">', '<a href="$1">$2</a>', '<font style="color:$1">$2</font>', '<object width="660" height="405"> <param name="movie" value="'.str_replace("watch?v=", "v/", $1).'" /> <param name="allowFullScreen" value="true" /> <param name="allowscriptaccess" value="always" /><embed type="application/x-shockwave-flash" width="660" height="405" src="'.str_replace("watch?v=", "v/", $1).'" allowscriptaccess="always" allowfullscreen="true"></embed> </object>', ); return nl2br(preg_replace($search,$replace,$input)); } There is an error on code: <param name="movie" value="'.str_replace("watch?v=", "v/", $1).'" /> and on: <param name="allowscriptaccess" value="always" /><embed type="application/x-shockwave-flash" width="660" height="405" src="'.str_replace("watch?v=", "v/", $1).'" allowscriptaccess="always" allowfullscreen="true"> How can i use str_replace in this situation ? :S Does anyone know of a json or php method of authenticating a youtube user without using zend? Code: [Select] <?php $id = NULL; $username = 'myYouTubeAccount'; $url = 'http://gdata.youtube.com/feeds/api/users/%s/uploads?orderby=updated&max-results=8'; $xml = simplexml_load_file(sprintf($url, $username)); foreach ($xml->entry as $entry) : $kids = $entry->children('http://search.yahoo.com/mrss/'); $attributes = $kids->group->content[0]->attributes(); $flv = $attributes['url']; $attributes = $kids->group->player->attributes(); $link = $attributes['url']; $querystring = parse_url($link,PHP_URL_QUERY); parse_str($querystring, $id_temp); $id = $id_temp['v']; ?> <a href="<?=$link?>"> <img src="http://i4.ytimg.com/vi/<?=$id?>/default.jpg" /> </a> <?php endforeach; ?> Hi, Have a project, http://ziz.im URL Shortener. For some reason, shortened youtube links don't work. When used, they go to the youtube page, displaying a message saying the video is not available. But it's the same link (once redirected) as the original link. Any idea what could be causing this ? Hi, Would time() produce the timestamp based on your time environment or the servers?, if it produces the timestamp based on the server; how would I generate a timestamp (which I can later use within date()); so it displays to the users timezone? Code: [Select] if ($showigiteidimage) { $igitwid_divlnk = "onclick=location.href='" . get_permalink($igitwid_result->ID) . "'; style=cursor:pointer;"; $igitwid_output .= '<li id="igit_wid_rpwt_li" style="height:' . $igitwid_height . 'px; padding-bottom: 10px;" ' . $igitwid_divlnk . '>'; $igitwid_output .= '<div id="igit_wid_rpwt_main_image" style="float:left;"> <a href="' . get_permalink($igitwid_result->ID) . '" target="_top"><img src="<?php $values = get_post_custom_values("tj_video_img_url"); echo $values[0]; ?>" id="igit_rpwt_thumb" ></a></div>'; the prb is image src cant read the php code , what to do ? please helpppppppppp Ok, so I have a code that looks like so: Code: [Select] <script type="text/javascript"> var ng_config = { assests_dir: 'ng/assets/' // the path to the assets directory } </script> <script type="text/javascript" src="ng/ng_all.js"></script> <script type="text/javascript" src="ng/components/calendar.js"></script> <script type="text/javascript"> var my_cal; ng.ready(function(){ // creating the calendar var my_cal = new ng.Calendar({ input: 'enddate', start_date: 'year - 1', // the start date (default is today) display_date: ng.get('startdate').value, // the display date (default is start_date) server_date_format: 'm/d/Y' // changing the server date format for a specific calendar. }); }); var my_cal1; ng.ready(function(){ // creating the calendar my_cal1 = new ng.Calendar({ input: 'startdate', start_date: 'year - 1', // the start date (default is today) display_date: new Date(), // the display date (default is start_date) server_date_format: 'm/d/Y' // changing the server date format for a specific calendar. }); }); how do I detect the months that pass between the two dates that are selected using a popup calendar using php so that my register page know which month to display the event under. Does this make sense? Hello. Would php be the right thing to use in regards to monitoring changes in html on certain pages, Basicly, I'd need it to be something like: "Page last changed: 2 Days, 4 Hours, 34 Minutes and 13 Seconds ago." What would I use for this? Thanks I am making a demo page that I want to add a form to. The way I want this for to work is. Say you are at demo.com Now you are a client I am working with so I have given you a number. This form will as for that number and on submit it will take you to demo.com/"client number" Here is what I have done. What is in my index.php <form> <form action="search.php"> <input id="button" name="button" type="text" /> <input type="button" value="SEARCH" > </form> What is in my search.php <?php $newurl = "http://demo.mysite.com/"; $newurl .=$_GET['button']; echo "$newurl"; /*header("Location: $newurl"); */ ?> -------------------------------------------------- I have also tried taking out the search.php and having everything in index.php <form> <form> <input id="button" name="button" type="text" /> <input type="button" value="SEARCH" > </form> <?php $newurl = "http://demo.mysite.com/"; $newurl .=$_GET['button']; echo "$newurl"; /*header("Location: $newurl"); */ ?> hi guys, i am trying to create a button that when u press if in the text are will appear <video>...</video> i know this is js do don't worry i will manage to do it, my problem is in php, i did a function that recognizes the link between <video>...</video> and then it embades it and shows me a youtube video instead, the problem i got is that if i have in the text area more <video>...</video>, like: bla bla bal<video>youtube link</video> and the other vid <video>youtube link</video> i dont know how to make it embade both, i dont know how to check if there is more, and the second problem i got is that all the text that was not betwen <video>...</video> will disapear after the vide is embadded, here is the code i done until now Code: [Select] <form action="test1.php" method = "POST"> <textarea name="body" id="text" cols="30" rows="10"></textarea> <input type="submit" value = "submit"> </form> <?php function video($string){ preg_match_all("#<video\b[^>]*>(.*?)</video>#", $string, $output); preg_match_all("#(?<=v=)[a-zA-Z0-9-]+(?=&)|(?<=v\/)[^&\n]+(?=\?)|(?<=v=)[^&\n]+|(?<=youtu.be/)[^&\n]+#", $output[0][0], $match); return "<iframe width='560' height='315' src='http://www.youtube.com/embed/".$match[0][0]."' frameborder='0' allowfullscreen></iframe>"; } if (isset($_POST['body'])&&!empty($_POST['body'])) { $body = $_POST['body']; print_r(video("$body")); } ?> |