【问题标题】:How to upload a folder of images using php and mysql如何使用 php 和 mysql 上传图像文件夹
【发布时间】:2016-03-22 02:14:21
【问题描述】:

基本上我必须通过 mysql 和 php 使用 xampp 创建一个点唱机类型图表。 我已经完成了设置表的基础知识,我引用了 mysql 数据库等。我只是不知道如何编写我创建的图像文件夹的路径。我的 Image 文件夹位于我创建的名为 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 创建这个路径

【问题讨论】:

    标签: php mysql sql xampp


    【解决方案1】:
    <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>";
     }
    

    【讨论】:

    • 谢谢,它成功了,但在专辑封面列中,每个引用的图像都显示为一个撕裂图像的小图标
    • 这是你应该在 css 中做的事情
    • 用css做简单的边框
    • 你能帮我解决另一个关于在我的播放列中上传 mp3 的问题吗,比如我将如何将它放入编码中?我假设它类似于专辑编码
    • 你能帮忙吗?
    【解决方案2】:

    不需要做任何特别的事情。您正在使用base directory/jukebox/ 工作,您的图像位于/jukebox/img/。让我们让它工作:

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

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

    【讨论】:

    • 我会把这个放在我的编码中的什么地方?
    • 你能在我当前的编码中更具体的位置吗?因为它在我放置的地方不起作用,抱歉。
    • @NahedahAhmed 您可能希望在循环中包含它,以便您可以正确引用该行,例如:&lt;td&gt;" . $row["Albumcover"] ."&lt;/td&gt;
    • 我已经尝试过了,但它对我不起作用......我把它放在一起像这样 " . $row["Albumcover"] 。" echo '';
    • @NahedahAhmed 您不能在concatenated string 中嵌入echo。我不知道你不知道这些事情,对不起。我已经编辑了我的答案,并提供了您应该放在 &lt;td&gt;&lt;/td&gt; 标记之间的确切代码。
    猜你喜欢
    • 2021-09-29
    • 2023-04-01
    • 2022-08-10
    • 2016-06-17
    • 1970-01-01
    • 1970-01-01
    • 2014-02-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多