如何使用 php 和 mysql 上传图片文件夹

How to upload a folder of images using php and mysql

基本上我必须通过 mysql 和 php 使用 xampp 创建点唱机类型的图表。 我已经完成了设置 table 我指的 mysql 数据库等的基础知识。我只是不知道如何编写我创建的图像文件夹的路径。我的图像文件夹位于我创建的名为 Jukebox 的文件夹下的 htdocs 中。这是我的编码:

<!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>" . $row["Albumcover"] 
         . "</td>
         <td>" . $row["Play"] . "</td>

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

} else {
     echo "0 results";
} ?>         
</body>
</html>

This is what my php coding looks like

This is my image folder which i wish to create a path to so that all the album art can come up in the albumcover column

如何使用 php 和 mysql 创建此路径

不需要做任何特别的事情。您正在 /jukebox/base directory 中工作,您的图像驻留在 /jukebox/img/ 中。让我们让它发挥作用:

<img src=\"/jukebox/img/".$row['Albumcover']."\"/>

在你的循环中。现在专辑封面将显示为该行中的图像。

<style>
.preview
{
    width:400px;
    border:solid 1px #dedede;
    padding:10px;
    color:#cc0000;

}
</style>
<?php
 // 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 class='preview' src='jukebox/img/" . $row["Albumcover"] ."' alt=".$row["Albumcover"]."></td>
     <td>" . $row["Play"] . "</td>

     </tr>";
 }