我是我的數據庫中的圖像數據作爲mediumblob並試圖檢索它作爲圖像時,用戶通過它的相應的ID選擇圖片。在任何人跳過我的喉嚨之前,是的,我意識到這是一個更順暢的過程,存儲在文件服務器上,並以這種方式檢索,但這是一個班級,這是教授想要的。獲取「圖像無法顯示,因爲它包含錯誤」
<HTML>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>BLOB Data Type Tutorial</title>
</head>
<body>
<form action="images.php" method="POST" enctype="multipart/form-data">
Select Picture: <input type="pictureID" name="pictureID"> <input type="submit" value="submit" name="submit">
</form>
<?php
$link = mysqli_connect('127.0.0.1:3306','user','');
$link;
mysqli_select_db($link, "media");
$sql = "SELECT * FROM images";
$result = mysqli_query($link,$sql);
echo "<table>";
echo "<tr><th>Picture</th><th>Size KB</th><th>Title</th></tr>";
if($result === FALSE){
echo "failed";
die(mysql_error());
}
while($row = mysqli_fetch_array($result)) {
$Picture = $row['Picture'];
$Size = $row['Size KB'];
$Title = $row['Title'];
echo "<tr><td style ='width: 50px;'>".$Picture."</td><td style='width: 60px;'>".$Size."</td><td>".$Title."</td></tr>";
}
echo "</table>";
if(isset($_POST['pictureID']))
{
$imgId = $_POST['pictureID'];
echo $imgId;
if (!empty($imgId)) {
$sqliCommand = "SELECT Picture FROM images WHERE Picture = $imgId";
$result = mysqli_query($link, $sqliCommand);
$row = mysqli_fetch_assoc($result);
header("Content-type: image/jpeg");
echo $row['Image'];
}
}
else
{
echo "^ Please select a picture! ^";
}
?>
<br>
<h4>
<a href="./index.html">Main Menu</a> <br>
</h4>
</body>
</HTML>
任何提示/幫助表示讚賞!
找一位新教授。他真的不知道他在教什麼,如果那是他想要你學習的東西。有許多事情是錯誤的,不僅僅是圖像數據在數據庫中的存儲,還有缺乏準備好的語句(用戶輸入),表格中的輸出(儘管如果存在大量具有相應數據的圖像,這可能是有保證的這應該是可比的/可排序的)。 – junkfoodjunkie