getDownloader($youtubeURL); // Set the url $downloader->setUrl($youtubeURL); // Validate the youtube video url if($downloader->hasVideo()){ // Get the video download link info $videoDownloadLink = $downloader->getVideoDownloadLink(); $videoTitle = $videoDownloadLink[0]['title']; $videoQuality = $videoDownloadLink[0]['quality']; $videoFormat = $videoDownloadLink[0]['format']; $videoFileName = strtolower(str_replace(' ', '_', $videoTitle)).'.'.$videoFormat; $downloadURL = $videoDownloadLink[0]['url']; // $fileName = preg_replace('/[^A-Za-z0-9.\_\-]/', '', basename($videoFileName)); if(!empty($downloadURL)){ // Define headers header("Cache-Control: public"); header("Content-Description: File Transfer"); header("Content-Disposition: attachment; filename=$fileName"); header("Content-Type: application/zip"); header("Content-Transfer-Encoding: binary"); // Read the file readfile($downloadURL); } }else{ echo "The video is not found, please check YouTube URL."; } }else{ echo "Please provide valid YouTube URL."; } } ?>