好吧,所以我知道這個問題已被問到,但我仍然無法弄清楚我的代碼出了什麼問題。Blob數據PHP破碎的圖像?
我想將圖像上傳到數據庫並將其存儲爲blob,以便它可以在頁面上輸出。一切正常,一切都存儲在mysql數據庫中,但當我試圖回顯blob時,它會給我一個破碎的圖像。這是我的代碼。
$file = $_FILES['image']['tmp_name'];
if(!isset($file)) {
echo "Please select image.";
} else {
$image = addslashes(file_get_contents($_FILES['image']['tmp_name']));
$image_name = $_FILES['image']['name'];
$image_size = getimagesize($_FILES['image']['tmp_name']);
if($image_size==FALSE) {
echo 'that is not an image.';
} else {
if (!$insert = mysql_query("INSERT INTO photo VALUES ('', '$image_name', '$image')")) {
echo "Problem uploading image";
} else {
$lastid = mysql_insert_id();
echo "Image uploaded.<p />Your image:<p /><img src=ShowPics.php?id=$lastid>";
}
}
}
?>
<form action="Photosite.php" method="POST" enctype="multipart/form-data">
<input type="file" name="image"></br></br>
<input type="submit" value="Submit">
</form>
我的PHP頁面
<?php
$id = addslashes($_REQUEST['id']);
$image = mysql_query("SELECT * FROM photo WHERE id=$id");
$image = mysql_fetch_assoc($image);
$image = $image['image'];
header("Content-type: image/jpeg");
echo $image;
?>
任何幫助表示讚賞???我只是不明白爲什麼我得到一個破碎的圖像...
[**請不要在新代碼中使用'mysql_ *'函數**](http://bit.ly/phpmsql)。他們不再被維護[並被正式棄用](https://wiki.php.net/rfc/mysql_deprecation)。看到[**紅框**](http://j.mp/Te9zIL)?學習[*準備的語句*](http://j.mp/T9hLWi),並使用[PDO](http://php.net/pdo)或[MySQLi](http://php.net/ mysqli) - [這篇文章](http://j.mp/QEx8IB)將幫助你決定哪個。如果你選擇PDO,[這裏是一個很好的教程](http://j.mp/PoWehJ)。 –
謝謝你會做,我知道這些,但只是沒有得到他們。 –