Download video tag

Asked

Viewed 416 times

1

I need to have a video download button, I have no idea how I can do this.

<video id="videoDownloadLink" style="max-height:320px;" width="100%" controls>
    <source src="<?=$video?>" type="video/mp4">
</video>


<button onclick="myFunction()" id="submit"> Downdload </button>

And to download I’m trying with download js but it’s not working, someone knows a better way to download the video

function myFunction() {         
    var x=new XMLHttpRequest();
    x.open("GET", "<?=$video?>", true);
    x.responseType = 'blob';
    x.onload=function(e){download(x.response, "dlBinAjax.mp4, video/mp4" ); }
    x.send();
}   

It is possible to have the programming of this button, in another button created by me?

inserir a descrição da imagem aqui

2 answers

0


I managed to solve

<a style="background-color: #8890A6; color: #fff; cursor: pointer; border-radius: 5px; text-align: center; padding: 5px;" href="download.php?nome=<?=$dado['profileInfo']['firstName']?>&sobrenome=<?=$dado['profileInfo']['lastName']?>&video=<?=$video?>" target="_blank">Download </a>

download php.

<?
    $actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
    $links = explode("&video=", $actual_link);

    $nome=$_GET['nome'];
    $sobrenome=$_GET['sobrenome'];


    //$file_url = "https://d28je5hezfy7mw.cloudfront.net/dev/videos/pitches/full/ee8b25e4-8abf-4699-a321-eca104eee67c?Expires=1573671424&Signature=ncqYk~rEV9MhOKnjGTELqyW52wt11gqmJ3z55jv5zGc84bowBAFtoPbgvONlJn5uWk~r2fC1QEZVkoYRDkRBzNJXN-caAotY1cTTTMaUA4DFFp6sVe0akeKdJs-mfy0o~UN1jwM3IxNunNiXsrH~EkJuJJFf2TOICsHAv3LDO0rlAbMzF7w~CPqAx3M5P-cMLZOOm6gT6Kg9NwEUaGdKMYrTWHPx-S~DROPBHLZ7Ahj9w6urqEEpSWmgDcerHJlZBKgwir9ttWl7evklBc~xIZA4q6imNgOx0mC~vvghtyQQSnQGB7mm~ImCJmShvhKfKiv9adSrkCcP4CYC9eHHig__&Key-Pair-Id=APKAJNVL777XIHTPI2BA";
    $file_url = $links[1];
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename="'.basename($nome." ".$sobrenome).'.mp4');
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file_url));
    header("Content-Type: video/mp4");
    flush(); // Flush system output buffer
    readfile($file_url);

?>

-1

In this way it worked as requested. There is a new feature, the

download

that allows you to download any type of file.

Concept( How it works ): download

<a class="site-btn sb-light" href="teste/The 30-Second Video.mp4" target="_blank" download>Download</a>

I hope it helped!

MD

  • yeah, but there’s a problem, I don’t have the video on the server, I’m working with api

  • you can always put the video online and private and use URL instead of file!

  • I didn’t get it, I api is just passing the video link, if I <a class="site-btn Sb-light" href="<?= $video? >" target="_Blank" download>Download</a> opens only the video

  • https://stackoverflow.com/questions/20222769/download-own-videos-in-the-youtube-api

  • Ricardo, did you try to do as Marcelo said? Try to create a link and add the attribute download and tell us if it worked. Ex.: <a href="<?= $video ?>" download>Download</a>

  • Marcelo, it would be nice if you edit your reply and add more information about your solution and explain more about it... and don’t forget to always link to documentation of the concepts you are using, so your answer gets better. ;)

  • done. Thank you

  • Fernando, create a link like, I didn’t notice " <a class="site-btn Sb-light" href="<?= $video? >" target="_Blank" download>Download</a> " I have this, video variable is passing the URL of the video, when I click on the button to download just open the video in new window

  • video link passed by API -> https://d28je5hezfy7mw.cloudfront.net/dev/videos/pitches/full/be6f1f4d-5d94-49cb-a94f-2c09fcf66cc6?Expires=1573657949&Signature=4JleFSiprtp0DEcWP2b25Aas9Ac6CQgWRvaNDuT5yerg4ft-aK2CpaPuOGOSJ01h0fSKrOn3LVVGnpkscwiHwlxBabGK5pWp5as~L3Ykr6aOmz5kSmlDSggsgyKa2wdDybaZcDqGxsHDlb~FHDKX6TwfY8gt5RViTR0sD0~fsoQkP-tjWWRFyy1Hy1l9HbidrKKQRl4Nrme3BeLSzOD39LzAH9k1Z09ycNshnADqPnQGpMt44r8qDsAxjC7qSrHUodCADffGLdgRzoRkFo4F8rS~tpsSUazWznF4SfDcyvU-Seq7pm-dhWAUvzvt2C46O0NXoyWorOVbBYLzxIaAg__&Key-Pair-Id=APKAJNVL777XIHTPI2BA

Show 4 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.