php - 我如何使用 php 和 mysql 上传音乐

标签 php mysql audio xampp localhost

我创建了一个表,其中包含我的音乐信息和专辑封面。我一直在使用 Mysql 和 PHP 来创建表并实现图像。我不明白如何将我的音乐上传到这张 table 上?有人可以帮忙吗?

我需要在播放栏中显示和播放我的音乐。

As you can see, on the far right is the play column and the names of the mp3 files are in the play column as well

And this is where my audio files are

这是我的编码:

<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
     border: 1px solid black;
}
</style>
</head>
<body>

<?php

$servername = "localhost";
$username = "root";
$password = "";
$dbname = "jukebox";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
     die("Connection failed: " . $conn->connect_error);
} 


$sql = "SELECT * FROM Music";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
     echo "<table>

     <tr>

     <th>Artist</th>
     <th>Title</th>
     <th>Album</th>
     <th>Albumcover</th>
     <th>Play</th>
     </tr>";


// output data of each row
     while($row = $result->fetch_assoc()) {

         echo 

         "<tr>

         <td>" . $row["Artist"]. "</td>
         <td>" . $row["Title"]. "</td>
         <td>" . $row["Album"]. "</td>
         <td><img src='/jukebox/img/" . $row["Albumcover"] ."' alt=".$row["Albumcover"]."></td>
         <td>" . $row["Play"]  . "></td>



         </tr>";
     }
     echo "</table>";



} else {
     echo "0 results";
}



?>  


</body>
</html>

最佳答案

尝试这样的事情

echo "<tr>
            <td>" . $row["Artist"]. "</td>
            <td>" . $row["Title"]. "</td>
            <td>" . $row["Album"]. "</td>
            <td><img src='/jukebox/img/" . $row["Albumcover"] ."' alt=".$row["Albumcover"]."></td>
            <td>
               <audio controls>
                  <source src='pathToAudioFile.mp3' type=\"audio/mpeg\">
                Your browser does not support the audio element.
                </audio>
            </td>
         </tr>";

还要确保音频文件权限设置正确

关于php - 我如何使用 php 和 mysql 上传音乐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36146044/

相关文章:

php - SaaS 应用程序从头开始

php - 为什么在使用\b 字边界时使用 = 或 "break PHP regex 等特殊字符?

python - 读取音频wav文件并绘制在python中平滑的音频频率响应

flash - 多个Flash应用程序可以同时访问麦克风吗?

iphone - 如何在多个 View 和恢复控件中使用AVPlayer?

php - 如何将一个类添加到一个动态菜单项?

php - 从服务器 MySQL 数据库创建 SQLite 版本

php - 从 MySQL 中提取数据并在页面之间分解

mysql - 从两个表中检索数据时如何填充文本框?

php - .htaccess RewriteRule 保留 GET URL 参数