好吧,所以我知道这个问题已被问到,但我仍然无法弄清楚我的代码出了什么问题。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)。 –
谢谢你会做,我知道这些,但只是没有得到他们。 –