How to Get Thumbnail From Youtube Video Using PHP

Sometime it’s necessary to display the Thumbnail Image of a youtube video from URL. So in this tutorial am going to example you how to get the thumbnail image of a video from youtube. Here am using PHP to obtain the output. You may also like How to Fullscreen Background Video Using HTML And CSS and Multiple Image Upload in PHP.

HTML Code

<html>
    <head></head>
    <body>
        <form method="post" action="">
            <input type="text" name="url" placeholder="Enter URL">
            <input type="submit" name="get_thumbnail" value="GET THUMBNAIL">
        </form>
    </body>
</html>

PHP Code

<?php
if(isset($_POST['get_thumbnail']))
{
    $url=$_POST['url'];
    $fetch=explode("v=", $url);
    $videoid=$fetch[1];
    echo '<img src="http://img.youtube.com/vi/'.$videoid.'/0.jpg" width="250"/>';
}
?>

Leave a Reply

Your email address will not be published. Required fields are marked *