PHP returns an MP3 file [closed]

0

I have a small music application where files are loaded from a URL like " link ".

Locally the application works very well.

But when I put it on the server my application generates an error in the browser console.

  

Uncaught InvalidStateError: Uncaught InvalidStateError: An attempt was   made to use an object that is not, or is no longer, usable.

My PHP code:

 $song_name = $_GET['name'];
 $song_file = "{$_SERVER['DOCUMENT_ROOT']}/assets/musics/{$song_name}.mp3";

 if( file_exists( $song_file ) )
 {
    header("Content-Type: audio/mpeg, audio/x-mpeg, audio/x-mpeg-3, audio/mpeg3");
    header('Content-Length: ' . filesize($song_file));
    header('Content-Disposition: attachment; filename="'.$song_name.'.mp3"');
    header("Content-Transfer-Encoding: binary");      
    header('X-Pad: avoid browser bug');        
    readfile( $song_file );
  } 
    
asked by anonymous 12.09.2014 / 19:21

1 answer

1

Well, we have two points, the first one is, if you can access the file directly from the link you are making the request, then if you can reproduce, and if you are calling your file for a js, check the what is happening with your ajax, or even with your frame, that you are altering. As I do not know your environment, I suspect that the problem is in the configuration of your server or your .htacess, where your header may be being ignored.

    
12.09.2014 / 23:34