【发布时间】:2014-08-18 13:45:20
【问题描述】:
我有一个小音乐应用程序,文件从“http://www.mymusicapp.com/get_song.php?name=SOME_MUSIC”之类的 URL 加载。该应用程序在本地运行良好!但是当我将它放在服务器上时,我的应用程序会在浏览器控制台中生成错误。
浏览器错误 未捕获的 InvalidStateError:尝试使用不可用或不再可用的对象
我的 PHP 代码是:
$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 );
}
【问题讨论】:
-
在readfile之前尝试exit检查是否有错误
标签: php error-handling mp3