-1
我想在数据库中插入图像,但由于某些原因,我无法检索它。我在数据库中使用BLOB类型的图像。PDO在数据库中插入图像并检索图像
我正在使用上传图片的代码。有一次,我保存图像数据库,在“形象”专栏中,我得到我使用的打印网页图像文件图像01.bin
if (isset($_POST["submit"]) {
$id= $_GET["id"];
$image = $_POST["image"];
$stmt=$conn->prepare("INSERT INTO db (id, image) VALUES (:id, :image)");
$stmt->bindParam(:id, $id);
$stmt->bindParam(:image, $image);
$stmt->execute();
}
代码。
$stmt = "Select Id, Image from db where id = $id LIMIT 0,1"
$q = $conn->query($stmt);
while ($r = $q ->fetch():
echo "<img src ='",$r[Image],"' width='100' height='100' />";
endwhile;
二进制图像数据是“in”$ _POST ['image']?可能的,但是......你是怎么做到的? – VolkerK 2015-01-21 09:02:01
你必须阅读的图像内容把它放在一个blob ...看看http://stackoverflow.com/questions/23854070/pdo-insert-image-into-database-directly-always-inserting-blob-0b – 2015-01-21 09:02:01
'echo“”;'在这个php文件中加入适当的mime类型 – 2015-01-21 09:03:02