PHP Download MP3 File by URL

On June 1, 2012, in CURL, LAMP, Learning, PHP, Tips, Web Streaming, by Sandeep Verma


Hits: 3459  

PHP Download MP3 File by URL

1. WGET
It will save files on web server then use php header for prompting to download file.

2. CURL
CURL will not work efficiently for big files i.e. MP3, ZIP, MP4 etc.

3. file_get_contents()
This will consume too much memory on server. It can first read remote URL then save and download.

4. Content-type: application/x-file-to-save

<?php

if(isset($_REQUEST['inputurl']) && $_REQUEST['inputurl']!="") {

$file = $_REQUEST['inputurl']; 

header("Content-type: application/x-file-to-save"); 
header("Content-Disposition: attachment; filename=".basename($file)); 
readfile($file); 

}

?>

<form name="from" method="post" action="">
<input name="inputurl" type="text" id="inputurl"  value="" />
<input type="submit" name="Button1" value="Get File" id="Button1" />
</form>

Demo: http://demo.svnlabs.com/download/



  • mark

    a good working code

  • CM

    I have found it finally php download mp3 :) Thanks.

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...