json - PHP Youtube downloader API Download file name videoplayback
891
I am using Youtube download API when i click on download button video is downloading but filename showing "videoplayback.MP4" My code:
<?php
$url="http://hddir.com/ajax/api.php?type=downlink&v=Is3S-6hHQLk";
$c=curl_init();
curl_setopt($c,CURLOPT_RETURNTRANSFER,1);
curl_setopt($c,CURLOPT_URL,$url);
$contents=curl_exec($c);
curl_close($c);
$someObject = json_decode($contents);
foreach($someObject as $obj){
$url=$obj->url;
$format=$obj->format;
echo '<a href="'.$url.'" download>video '.$format.'</a></br>';
}
?>
Result result of above code
Answer
Solution:
As a quick fix, HTML5 provides a
download
attribute you may use in your anchor tag, this allows you to specify the desired file name of the download. This relies on the end user using a browser which supports this tag.At the time of writing browser support is:
There is no requirement to specify a file extension.
More information can be found online including browser support, for example this W3 Schools Article
Update: This will not work cross-origin, the file must be hosted on the same domain, as such this is not a solution for this particular problem unfortunately.