Create a link to download music or video

I have an html file with video and audio files. and I want to link a file, such as mp3 or mp4, using the href tag and upload this file. My video and audio file stored in the same folder with my html file.

I tried this code:

<a href="music/hermin.mp3" target="_blank">download</a> 

but not downloaded my file, just open a new tab with pause playback controls in the center.

from this question, I can add the “upload” to my href tag, but this is for a modern browser. How about an old browser?

how can I create a link to download my video / audio in an html file and support for the entire browser (not only for a modern browser)?



thanks in advance and sorry for my bad english.

+6
source share
2 answers

It depends on your browser settings and plugins, however, if you use php, you can make a script to download a file like this:

 <?php if (isset($_GET['file'])) { $file = $_GET['file'] ; if (file_exists($file) && is_readable($file) && preg_match('/\.mp3$/',$file)) { header('Content-type: application/mp3'); header("Content-Disposition: attachment; filename=\"$file\""); readfile($file); } } else { header("HTTP/1.0 404 Not Found"); echo "<h1>Error 404: File Not Found: <br /><em>$file</em></h1>"; } ?> 

save it as download.php

then create a link like this

 <html> <body> <a href="download.php?file=test.mp3">download</a> </body> </html> 

Now he must work, have a good day.

+6
source

You can try this. I tried and it works for me.

 <a href="link/to/your/download/file" download> Download link </a> 
+30
source

All Articles