1

I have both .mp3 and .pcm audio format on my server, how should I set the php header content-type when I don't know which type the user has requested for?

Blake
  • 7,367
  • 19
  • 54
  • 80
  • 4
    How *could* you not know which type the user has requested for? – Alvin Wong Nov 15 '12 at 09:04
  • i CAN know, but in my system, the user's request doesnt contain the audio format info, i need to retrieve that info from db, so i m seeking if there is a simple way. – Blake Nov 15 '12 at 09:08

4 Answers4

1

Yes you have to .. you can use mime_content_type to Detect MIME Content-type for a file simplify the process in your header

Example

header(sprintf('Content-type: %s',mime_content_type($filename)));
Baba
  • 94,024
  • 28
  • 166
  • 217
0

I guess you can just use "Application/octet-stream" for any type of binary file format.

Jan.
  • 1,925
  • 15
  • 17
0

When you say you set the header the i think your rewrite your .mp3 and .pcm to a PHP-Script.

In this case you should rewrite it with the file extension. Then you can check the extension in your $_GET variable.

if(strpos('.mp3', $_GET['filename']) !== false) {
   header('Content-Disposition: inline;filename="test.mp3"');
}

if(strpos('.pcm', $_GET['filename']) !== false) {
   header("Content-type: application/octet-stream;");
}

PCM data is RAW-Data so i think you can use octet-stream or the cool solution from Baba

So you can check which format it is and set the header for the specified file.

Here is another post to this problem: Output mp3 with php

Community
  • 1
  • 1
René Höhle
  • 26,716
  • 22
  • 73
  • 82
0

In my site i used this type of header. I suggests this one.

Example

header("content-type:text/xml;charset=utf-8;charset=windows-1256");

Rithu Psks
  • 92
  • 11