2015-02-14 4 views
1

Я сослался на эти вопросы и внедрил их ответы, но ни один из них не работает для меня.Скачать mp3-файл у браузера Android

download mp3 instead of playing in browser by default?

PHP Streaming MP3

content type for mp3 download response

download mp3 from web url with android failed

В принципе, когда пользователь нажимает на ссылку для загрузки на веб-сайте, мы хотим, чтобы пользователь будет предложено загрузить аудиофайл.

Код:

header("Pragma: public"); 
header("Expires: 0"); 
header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
header("Cache-Control: public"); 
header("Content-Description: File Transfer"); 
header("Content-Type: $mtype");   
header("Content-Disposition: attachment; filename=".$file_name); 
readfile($fname); 
header("Content-Transfer-Encoding: binary"); 
header("Content-Length: " . $fsize); 

Здесь $mtype является "audio/mpeg"

Success:

  1. Он работает отлично на всех настольных браузеров.
  2. Я пробовал с BlackBerry, и я получил загруженный файл.

Failure:

  1. когда я сделать то же самое с андроид браузеров, я did't получить загруженный файл.
  2. имя файла также отсутствует, содержит <untitled> и показывает статус "download unsuccessful".

Спасибо, если у вас есть идеи, почему этот код не работает на телефоне Android.

+0

Для начала попробуйте отправить заголовки перед выполнением 'readfile'. –

+0

@ N.B., Я тоже стараюсь, но не более успеха. –

ответ

0

с той же проблемой, и это может быть, что Ур-сервер не позволяет использовать MP3-файлы правильно (я использую Biz.nf)

0

Я только что нашел решение этой проблемы. На моем андроиде Xiaomi он работает отлично.

if (file_exists($file)) { 
    echo "OK"; 
    if (ob_get_level()) { 
    ob_end_clean(); 
} // clearing output script buffer 

$mime_type = "audio/mpeg, audio/x-mpeg, audio/x-mpeg-3, audio/mpeg3"; 
header('Content-Description: File Transfer'); 
header('Content-Type: {$mime_type}'); 
header('Content-Disposition: attachment; filename=' . basename($file)); 
header('Content-Transfer-Encoding: binary'); 
header('Expires: 0'); 
header('Cache-Control: must-revalidate'); 
header('Pragma: public'); 
header('Content-Length: ' . filesize($file)); 
readfile($file); 
Смежные вопросы