0
I have a small music application where files are loaded from a URL like "http://www.mymusicapp.com/get_song.php?name=SOME_MUSIC".
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 );
}
Your code is not at all safe Bruno, it is possible an attack of code Injection very easily.
http://www.mymusicapp.com/get_song.php?name=" echo "code injection é muito massa!"; $var = "
– gmsantos
Thank you for the gmsantos remark! But I would like to make him take it first of all. You would know how?
– Bruno Quaresma
The problem is not PHP, PHP does not send errors to the browser console (at least natively), much less errors of this nature. Your problem is in the Javascript code which is responsible for handling and playing the MP3. Your question in its current form is not possible to be answered exactly. Anyway, it looks to me like you’re using the object before it’s been loaded...
– Zuul