I’ve got an embedded mp3 player that i’m running in a webpage. When i load a physical mp3’s path as the file url, it works just fine, but when i try to load mp3 binary data from a php endpoint, it fails.
here’s what I’d doing to output the mp3 data via php:
//Begin writing headers
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:audio/mpeg');
header( 'Content-Disposition: inline;');
header( 'filename=SoundFile.mp3' );
header( 'Content-Transfer-Encoding: binary' );
//supply the length
$len = strlen($res['ReturnValue']);
header( 'Content-Length: ' . $len );
echo $res['ReturnValue']; exit();
// $res['ReturnValue'] is the actual binary data of the mp3
Also, when I run that php code in the browser, it causes a file download of the correct name and filesize, but the file itself wont play on anything (itunes / winamp / etc) as if it is corrupt.
What am I doing wrong with the output of this data that is causing it to not play in the embedded mp3 player?
The byte data was not being correctly output to me, thus, my headers were not the problem.