S
S
softrix2015-10-24 23:29:21
PHP
softrix, 2015-10-24 23:29:21

How to download mp3 using php?

I'm making a music player for a website.
There is a music archive, the user needs to give music through a php file.
Php loader looks like this:

$file = $_GET['music'];
$mp3 = file_get_contents($_SERVER['DOCUMENT_ROOT']."/".$file);
$file_size= filesize($_SERVER['DOCUMENT_ROOT']."/".$file);
header("Content-Type: audio/mpeg");
header("Accept-Ranges: bytes");
header("Content-Length: " . $file_size);  
echo $mp3;

From the computer everything works fine, the music plays. But from mobile browsers, nothing works. What could be the problem?
Mouzon trying to play through the audio tag
<audio src="download.php?music=test.mp3" controls type="audio/mp3" ></audio>

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
alegzz, 2015-10-25
@softrix

in Dolphin and Chrome the script works. By the way, what is the name parameter for?

A
Anton B, 2015-10-25
@bigton

Try like here

S
softrix, 2015-10-25
@softrix

Not really, download is not a problem. It is necessary that the file be played under smartphones, but it refuses to cut. And if it's a static mp3 file, then everything plays ok, but when I send the file through php, it doesn't play.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question