이 서버에서 mp3 파일 (예 : iTunes)에 대한 직접 액세스와 관련된 Google 웹 로그 분석에 통계를 추가하려고합니다. 이 PHP 함수를 실행하고 리다이렉션이없는 것처럼 파일을 전달하고 싶습니다.mp3 파일에 직접 액세스하기 전에 PHP 스크립트 실행
이 mod_rewrite 조각은 정상적으로 작동하는 것 같습니다. 내 현장 다운로드 스크립트 및 스트리밍 플레이어는 규칙을 실행하지 않고 mp3 파일에 액세스 할 수 있습니다.
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mysite\.com [NC]
RewriteRule ^audio/episodes/([^/\.]+).mp3$ /audio/episodes/google_analytics_mp3.php?mp3=$1&redirected=1 [L,QSA]
그러나 PHP 스크립트를 실행 한 후 mp3를 전달하려는 나의 초기 시도는 직접 액세스를 위해 파일을 제공하지 않습니다. 브라우저의 흰색 화면과 iTunes의 오류.
if ($id = intval($_REQUEST['mp3'])) {
$e = new Episode;
list($ep) = $e->retrieve("id = $id");
if ($ep) {
ga_send_pageview(basename($ep->audio_link), $ep->google_title());
if ($_GET['redirected'] == 1) {
$fileLocation = '/'.$ep->audio_link;
header("Location: $fileLocation");
exit();
}
}
}
또한 위치 헤더 이전
header('Content-Type: audio/mpeg');
를 전송했습니다. 같은 결과.
두 번째 시도는 브라우저 다운로드 파일을 첨부 파일로 만들어 iTunes와 같은 프로그램에서 작동하지 않으므로 원하는 결과가 아닙니다.
if ($_GET['redirected'] == 1) {
$fileName = basename($ep->audio_link);
$fileLocation = $_SERVER['DOCUMENT_ROOT'].'/audio/episodes/'.$filename;
header("Content-Transfer-Encoding: binary");
header("Content-Type: audio/mpeg, audio/x-mpeg, audio/x-mpeg-3, audio/mpeg3");
header('Content-length: ' . filesize($fileLocation));
header('Content-Disposition: attachment; filename="'.$fileName.'"');
header('X-Pad: avoid browser bug');
header('Cache-Control: no-cache');
readfile($fileLocation);
exit();
}
업데이트 : 당 마틴의 제안이 두 번째 방법을 시도했지만 처분과 header('Content-Disposition: inline; filename="'.$fileName.'"');
를 인라인으로 설정하지만 크롬은 그냥 흰색 화면을 보여줍니다. 방정식에서 스크립트를 제거하는 규칙을 사용 중지하면 Chrome이 기본 MP3 플레이어를 표시하고 파일을 재생합니다.
PHP 스크립트를 실행 한 후 어떻게 mp3 파일에 대한 일반 액세스를 허용 할 수 있습니까?
쿠키를 사용하십시오. – DanFromGermany
'Content-Disposition : inline'을 사용하여 브라우저에 또는 다운로드하도록 강제하지 않고 직접 MP3를로드하십시오. – Martin
@Martin에게 접근 방법은 무엇입니까? 위치 헤더 또는 두 번째 접근 방식을 사용합니까? – jerrygarciuh