PHP Youtube下载器API下载文件名videoplayback

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

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.

echo '<a href="'.$url.'" download="desiredfilename">video '.$format.'</a></br>';

At the time of writing browser support is:

  • Chome: 14.0
  • Edge: 13.0
  • Firefox: 20.0
  • Safari: 10.1
  • Opera: 15.0

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.