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

问题描述 投票:0回答:1

我创建了一个包含我的音乐信息和专辑封面的表格。我一直在使用Mysql和PHP来创建表并实现图像。我不明白我怎么会把我的音乐上传到这张桌子上呢?有人可以帮忙吗?

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

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>
php mysql audio xampp localhost
1个回答
0
投票

尝试这样的事情

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>";

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

© www.soinside.com 2019 - 2024. All rights reserved.