我已成功將圖像存儲在mySql中。我想檢索出來並在網站上顯示一個可以放大它的href按鈕。檢索並顯示來自MySql的圖像
這是我的數據庫表結構
-- Table structure for table `poster`
--
CREATE TABLE `image` (
`img_id` int(11) NOT NULL auto_increment,
`img_name` varchar(32) NOT NULL,
`img` blob NOT NULL,
`img_type` varchar(32) NOT NULL,
`img_size` int(255) NOT NULL,
PRIMARY KEY (`img_id`)
)
地顯示圖像
<div class="col-md-5 text-dimension">
<?php
$con=mysql_connect("localhost","root","");
mysql_select_db("isiti");
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysql_query("SELECT * FROM poster ORDER BY year DESC LIMIT 0, 5000");
while($row = mysql_fetch_array($result))
{
$id=$row['img_id'];
echo '<a href="img_disp.php?image_id='.$id.'" data-lightbox="image-1" title="©ISITI-CoERI"><center><img src="img_disp.php?image_id='.$id.'" alt="poster1" width="200" height="250"><br></a><br><br>';
echo '<span class=right><a href="edit_form.php?id='.$id.'">[edit]</a>
<a name="delete" id="delete" href="public_delete.php?id='.$id.'">[delete]</a></span>';
}
?>
這是img_disp.php
<?php
// Connect to the database
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="isiti"; // Database name
$tbl_name="poster"; // Table name
$conn = mysql_connect("$host", "$username", "$password");
if(! $conn)
{
die('Could not connect: ' . mysql_error());
}
if (isset($_GET["image_id"]) && !empty($_GET["image_id"]))
{
$id =$_GET["image_id"];
}
mysql_select_db($db_name);
$sql="SELECT * from poster where id='$id'";
$query=mysql_query($sql) or die(mysql_error());
while($result=mysql_fetch_array($query)){
header('Content-type:'.$result['img_type'].'');
echo $result['img'];
header('Content-Disposition: inline; filename="'.$result['img_name'].'"');
}
?>
問題是...圖像沒有顯示出來。爲兩者或彈出。
你不能在回聲後再做header()。必須先發送所有標題,然後才發送數據。 – RobP