文件上传

Signed-off-by: cssfw <16325875+cssfw@user.noreply.gitee.com>
This commit is contained in:
cssfw
2026-02-12 14:43:36 +00:00
committed by Gitee
parent e1bf62693a
commit 617e1a8771
18 changed files with 2014 additions and 0 deletions

46
music.php Normal file
View File

@@ -0,0 +1,46 @@
<?php
// music.php - 纯音频播放无HTML页面
// 允许跨域请求(可选)
header('Access-Control-Allow-Origin: *');
// 音频文件目录
$musicDir = 'music/';
// 支持的音频格式
$allowedExtensions = ['mp3', 'ogg', 'wav'];
// 获取目录下所有音频文件
$musicFiles = [];
foreach ($allowedExtensions as $ext) {
$files = glob($musicDir . '*.' . $ext);
$musicFiles = array_merge($musicFiles, $files);
}
// 随机选择一首歌
if (!empty($musicFiles)) {
$randomMusic = $musicFiles[array_rand($musicFiles)];
// 获取文件扩展名
$extension = pathinfo($randomMusic, PATHINFO_EXTENSION);
// 设置正确的Content-Type
$mimeTypes = [
'mp3' => 'audio/mpeg',
'ogg' => 'audio/ogg',
'wav' => 'audio/wav'
];
$contentType = $mimeTypes[$extension] ?? 'audio/mpeg';
header('Content-Type: ' . $contentType);
// 输出文件
readfile($randomMusic);
} else {
// 没有音频文件时返回静音音频
header('Content-Type: audio/mpeg');
// 这里可以返回一个静音的MP3文件
// 或者输出错误信息
echo 'No music files found';
}
?>