Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create download link for music or video

i have html file with video and audio file. and i want to links file such as mp3 or mp4 using tag a href and download that file. My video and audio file stored in same folder with my html file.

i have tried this code :

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

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

from this question i get to add "download" to my href tag, but it is for modern browser. How about for old browser?

how i can create a download link for my video/audio in html file and support for all browser (not only for modern browser)?



thanks in advance and sorry for my bad English.

like image 433
Yohanim Avatar asked Jan 06 '14 18:01

Yohanim


People also ask

How do I make a download link for a song?

To link to an MP3 file, you must first upload the MP3 file either to a cloud storage service like Google Drive or iCloud, or to an online music service like SoundCloud. After uploading the music, you can share it via the link.


2 Answers

You can try this. I've tried it, and it's working for me.

<a href="link/to/your/download/file" download> Download link </a>
like image 197
Emir Dupovac Avatar answered Oct 28 '22 23:10

Emir Dupovac


It depends of your browser settings and plugins however if you are using php you can do a script to download the file like this one:

<?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 one

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

It should work now, have a nice day.

like image 30
ELavicount Avatar answered Oct 29 '22 00:10

ELavicount