[identity profile] enemymaniac.livejournal.com posting in [community profile] useful_faq
Народ, я уже обгуглился, никак не могу разобраться.
Есть кнопка для скачивания файла в виде такого кода

//кнопка
$_array = array('img' => 'button_download.jpg',
'href' => os_href_link ('media/products'.$content_data['content_file']), 'alt' => TEXT_DOWNLOAD,

Однако при нажатии на нее файл (.mp3, если что) открывается браузером и проигрывается вместо того, чтобы скачиваться.

По хорошему-то я понимаю, что нужно куда-то пихать AddType application/octet-stream .mp3, в общем работать с mime-type, но что конкретно и куда?
В .htaccess прописывал, не работает. Помогите, пожалуйста.

Заранее спасибо.

Date: 2011-07-11 08:00 am (UTC)
From: [identity profile] karpion.livejournal.com
Это во всех браузерах так? Может, дело в настройках Вашего браузера?

Date: 2011-07-11 08:00 am (UTC)
From: [identity profile] solom.livejournal.com
Судя по всему, такую кнопку генерит используемый тобой фреймворк (для него-то видимо и создаётся эта структура).

В нём и ищи, где прописывается MIME-type.
Ещё вот это посмотри: http://php.net/manual/ru/function.header.php (но таки лучше во фреймворке, а то костыль получится).

Date: 2011-07-11 08:50 am (UTC)
From: [identity profile] ex-crigger-.livejournal.com
А сервер какой? Apache?

Date: 2011-07-11 09:05 am (UTC)
From: [identity profile] ex-crigger-.livejournal.com
На сервере))

В заголовках ответа сервера видно его имя. Если на сервере линукс - скорее всего апач или nginx.

Узнайте имя сервера и погуглите, как его сконфигурировать для правильной отдачи заголовков для mp3.
По-моему вам надо сделать так, чтобы файл шел как attached, если я не ошибаюсь.

Если будете отдавать application/octet-stream без аттачед - браузер будет проигрывать файл.

Date: 2011-07-11 09:07 am (UTC)
From: [identity profile] ex-crigger-.livejournal.com
Forcing SaveAs using the HTTP header

In order to force the browser to show SaveAs dialog when clicking a hyperlink you have to include the following header in HTTP response of the file to be downloaded:

Content-Disposition: attachment; filename=
[Error: Irreparable invalid markup ('<file name.ext>') in entry. Owner must fix manually. Raw contents below.]

Forcing SaveAs using the HTTP header

In order to force the browser to show SaveAs dialog when clicking a hyperlink you have to include the following header in HTTP response of the file to be downloaded:

Content-Disposition: attachment; filename=<file name.ext>

Where <file name.ext> is the filename you want to appear in SaveAs dialog (like finances.xls or mortgage.pdf) - without < and > symbols.

You have to keep the following in mind:

The filename should be in US-ASCII charset.
The filename should not have any directory path information specified.
The filename should not be enclosed in double quotes even though most browsers will support it.
Content-Type header should be before Content-Disposition.
Content-Type header should refer to an unknown MIME type (at least until the older browsers go away).

Date: 2011-07-11 03:28 pm (UTC)
From: [identity profile] smartgrinder.livejournal.com
Кроме того, файл можно и пыхпыхом отдавать, указав любые заголовки.