[英]How to upload a folder of images using php and mysql
基本上,我必須使用xampp通過mysql和php創建自動存儲塔類型圖表。 我已經完成了設置表的基本工作,涉及到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>
這是我的圖像文件夾,我希望創建該文件夾的路徑,以便所有專輯封面都可以出現在專輯封面列中
如何使用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>";
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.