PHP Download MP3 File by URL


Hits: 12779  

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>