久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

設置 apache 在請求 MP3 文件時為 PHP 提供服務

Setting up apache to serve PHP when an MP3 file is requested(設置 apache 在請求 MP3 文件時為 PHP 提供服務)
本文介紹了設置 apache 在請求 MP3 文件時為 PHP 提供服務的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在研究一種通過 PHP 提供 MP3 文件的方法,經過一些幫助形成如此龐大的文件,我讓它工作了 這里

I'm working on a way to serve up MP3 files through PHP and after some help form the SO massive, I got it working here

但是,當我將它用作這樣的音頻標簽中的源時,該示例似乎不起作用

However, that example doesn't appear to work when I use it as the source in an audio tag like this

<html>
    <head>
        <title>Audio Tag Experiment</title>
    </head>
    <body>

    <audio id='audio-element' src="music/mp3.php" autoplay controls>
    Your browser does not support the audio element.
    </audio>

    </body>
</html>

這里是 PHP

<?php

$track = "lilly.mp3";

if(file_exists($track))
{
header("Content-Transfer-Encoding: binary"); 
header("Content-Type: audio/mpeg, audio/x-mpeg, audio/x-mpeg-3, audio/mpeg3");
header('Content-length: ' . filesize($track));
header('Content-Disposition: filename="lilly.mp3"');
header('X-Pad: avoid browser bug');
Header('Cache-Control: no-cache');

readfile($track);
}else{
    echo "no file";
}

所以我在想(這可能是一個非常糟糕的主意,你告訴我)當有人請求 .MP3 時,我可能能夠設置 Apache 來提供 PHP 文件.

So I'm thinking (and this may be a really bad idea, you tell me) that I might be able to set up Apache to serve a PHP file when someone requests an .MP3.

所以我有三個問題

  1. 這行得通嗎
  2. 好主意/壞主意?
  3. 我需要做什么?將AddType application/x-httpd-php .mp3"放入 httpd conf 中可以嗎?

推薦答案

您的代碼中存在一些錯誤:

There are some errors in your code:

  • 一個資源只能有一個內容-輸入值.因此,您必須決定要使用的媒體類型.我建議 audio/mpeg.
  • 您忘記在內容中指定配置-處置.如果您只想提供文件名而不想更改配置,請使用默認值 inline.

其余看起來不錯.但如果找不到文件,我也會發送 404 狀態碼.

The rest looks fine. But I would also send the 404 status code if the file cannot be found.

$track = "lilly.mp3";

if (file_exists($track)) {
    header("Content-Type: audio/mpeg");
    header('Content-Length: ' . filesize($track));
    header('Content-Disposition: inline; filename="lilly.mp3"');
    header('X-Pad: avoid browser bug');
    header('Cache-Control: no-cache');
    readfile($track);
    exit;
} else {
    header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found', true, 404);
    echo "no file";
}

這篇關于設置 apache 在請求 MP3 文件時為 PHP 提供服務的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Joining 2 tables in SELECT(MYSQL/PHP)(在 SELECT(MYSQL/PHP) 中加入 2 個表)
How to make lt;option selected=quot;selectedquot;gt; set by MySQL and PHP?(如何使lt;option selected=“selectedgt;由 MySQL 和 PHP 設置?)
Auto populate a select box using an array in PHP(使用 PHP 中的數組自動填充選擇框)
PHP SQL SELECT where like search item with multiple words(PHP SQL SELECT where like search item with multiple words)
json_encode produce JSON_ERROR_UTF8 from MSSQL-SELECT(json_encode 從 MSSQL-SELECT 產生 JSON_ERROR_UTF8)
MySQL ORDER BY rand(), name ASC(MySQL ORDER BY rand(),名稱 ASC)
主站蜘蛛池模板: 久久久久久九九九九 | 日本三级做a全过程在线观看 | 国产精品电影在线观看 | 国产高清精品一区二区三区 | 午夜免费 | 国产欧美一区二区久久性色99 | 久久a久久 | 久久久久久国产 | 亚洲高清在线播放 | 91麻豆精品国产91久久久更新资源速度超快 | 亚洲一区二区在线 | 少妇精品亚洲一区二区成人 | 国产精品二区三区 | 久久精品毛片 | 成年女人免费v片 | 欧洲精品在线观看 | 国产日韩精品一区二区三区 | 婷婷激情综合 | 精品91久久| 黄a免费看 | 亚洲成人av一区二区 | 欧美在线激情 | 国产精品99精品久久免费 | 一二区视频 | 九七午夜剧场福利写真 | 影音先锋中文字幕在线观看 | 免费小视频在线观看 | 欧美日韩成人 | 亚洲精品中文在线观看 | 日本不卡免费新一二三区 | www.久久久久久久久久久久 | 精品福利在线 | 中文字幕av在线 | 黄色成人在线观看 | 日韩一区二区三区视频在线观看 | 日韩一区在线播放 | 午夜精品一区二区三区免费视频 | chinese中国真实乱对白 | 成人一区二区三区在线 | 成人一区av| 日本一区二区三区四区 |