关于在php和html混写
如下所示
<!DOCTYPE html>
<html>
<head>
<title>复古资源网</title>
<meta charset="UTF-8"> <!-- 添加字符编码声明 -->
</head>
<body>
<a href="https://modarchive.org/">复古mod音乐下载站</a>
<ol>
<?php
$directory = 'mod音乐收集'; // 实际目录路径
if (is_dir($directory)) {
$files = scandir($directory);
if ($files !== false) {
foreach ($files as $file) {
if ($file === '.' || $file === '..') continue;
$filePath = $directory . '/' . $file;
if (is_file($filePath)) {
// 处理中文路径编码:对路径中的每个部分单独编码
$encodedDir = implode('/', array_map('rawurlencode', explode('/', $directory)));
$encodedFile = rawurlencode($file);
$encodedPath = $encodedDir . '/' . $encodedFile;
// 创建带有下载链接的列表项
echo '<li><a href="' . htmlspecialchars($encodedPath) . '" download>'
. htmlspecialchars($file) . '</a></li>';
}
}
} else {
echo "<li>错误:无法读取目录内容</li>";
}
} else {
echo "<li>错误:目录不存在或不可访问</li>";
}
?>
</ol>
</body>
</html>
浙公网安备 33010602011771号