json - PHP Youtube downloader API Download file name videoplayback


I am using Youtube download API when i click on download button video is downloading but filename showing "videoplayback.MP4" My code:

$someObject = json_decode($contents);
foreach($someObject as $obj){
echo '<a href="'.$url.'" download>video '.$format.'</a></br>';

Result result of above code




As a quick fix, HTML5 provides adownload 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.

People are also looking for solutions to the problem: php - Consecutive calls callback called more times than expected


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.