Force Download MP3 with PHP -
be honest : found way donwload mp3 files s******d im not able donwload mp3 directly music streaming in browser.
i try someting this
<a href="direct_download.php?file=fineline.mp3">download mp3</a>
but donwload link not .mp3, line of code donwload file
href="<?php echo $val['stream_url']?>?client_id=67739332564a7130c3a05f90f2d02d2e">descargar</a>.
when use the option
direct_download.php?file=
just donwload 1 file name
client_id=05b4f2000dad27aa9fc48d08915d7830.html
the complete php code use is
<?php $file = $_get['file']; header ("content-type: octet/stream"); header ("content-disposition: attachment; filename=".$file.";"); header("content-length: ".filesize($file)); readfile($file); exit; ?>
which can accessed in anchor this:
<a href="direct_download.php?file=fineline.mp3">download mp3</a>
could please me, or if have better ide, thank guys
if using html5 can use download option
<a href="url_to_your_file.mp3" download>download mp3</a>
otherwise, can use javascript
function saveas(url) { var filename = url.substring(url.lastindexof("/") + 1).split("?")[0]; var xhr = new xmlhttprequest(); xhr.responsetype = 'blob'; xhr.onload = function() { var = document.createelement('a'); a.href = window.url.createobjecturl(xhr.response); a.download = filename; a.style.display = 'none'; document.body.appendchild(a); a.click(); delete a; }; xhr.open('get', url); xhr.send(); }
call link
<a href="javascript:" onclick="saveas(url_to_your_file.mp3)">download mp3</a>
Comments
Post a Comment