here is my handy feature for uploading a thumbnail of Youtube
function downloadYouTubeThubnailImage($youTubeLink='',$thumbNamilQuality='',$fileNameWithExt='',$fileDownLoadPath='') { $videoIdExploded = explode('?v=', $youTubeLink); if ( sizeof($videoIdExploded) == 1) { $videoIdExploded = explode('&v=', $youTubeLink); $videoIdEnd = end($videoIdExploded); $removeOtherInVideoIdExploded = explode('&',$videoIdEnd); $youTubeVideoId = current($removeOtherInVideoIdExploded); }else{ $videoIdExploded = explode('?v=', $youTubeLink); $videoIdEnd = end($videoIdExploded); $removeOtherInVideoIdExploded = explode('&',$videoIdEnd); $youTubeVideoId = current($removeOtherInVideoIdExploded); } switch ($thumbNamilQuality) { case 'LOW': $imageUrl = 'http://img.youtube.com/vi/'.$youTubeVideoId.'/sddefault.jpg'; break; case 'MEDIUM': $imageUrl = 'http://img.youtube.com/vi/'.$youTubeVideoId.'/mqdefault.jpg'; break; case 'HIGH': $imageUrl = 'http://img.youtube.com/vi/'.$youTubeVideoId.'/hqdefault.jpg'; break; case 'MAXIMUM': $imageUrl = 'http://img.youtube.com/vi/'.$youTubeVideoId.'/maxresdefault.jpg'; break; default: return 'Choose The Quality Between [ LOW (or) MEDIUM (or) HIGH (or) MAXIMUM]'; break; } if( empty($fileNameWithExt) || is_null($fileNameWithExt) || $fileNameWithExt === '') { $toArray = explode('/',$imageUrl); $fileNameWithExt = md5( time().mt_rand( 1,10 ) ).'.'.substr(strrchr(end($toArray),'.'),1); } if (! is_dir($fileDownLoadPath)) { mkdir($fileDownLoadPath,0777,true); } file_put_contents($fileDownLoadPath.$fileNameWithExt, file_get_contents($imageUrl)); return $fileNameWithExt; }
Function Description
Argumemts
$youTubeLink URL, for example https://www.youtube.com/watch?v=a3ICNMQW7Ok
$thumbNamilQuality Has many $thumbNamilQuality such as LOW ,MEDIUM, HIGH, MAXIMUM
Thumbnail Quality List Taken from fooobar.com/questions/1230446 / ...
&& fooobar.com/questions/1230446 / ...
$fileNameWithExt File name with extension **, for example ** myfavouriteimage.png
NOTE $fileNameWithExt is optional, it will generate a uuid based file name for Example 91b2a30d0682058ebda8d71606f5e327.jpg
if you want to put the file in a user directory, use this argument
NOTE $fileDownLoadPath is optional, it will generate an image file in which the script is executed
Some examples of examples
$folderpath = 'c:'.DIRECTORY_SEPARATOR.'xampp'.DIRECTORY_SEPARATOR.'htdocs'.DIRECTORY_SEPARATOR.'youtube'.DIRECTORY_SEPARATOR; $imageName = 'mybeautfulpic.jpg'; downloadYouTubeThubnailImage('https://www.youtube.com/watch?v=a3ICNMQW7Ok','MAXIMUM',null,$folderpath ); downloadYouTubeThubnailImage('https://www.youtube.com/watch?v=a3ICNMQW7Ok','LOW',$imageName ,null);
Hope the answer is already there, but this function has some exta features