php+mysql 图象输入输出
我看了网上的例子~用了~发现图片进数据库没问题~但是关于输出部分总是报错~
代码如下
建库:
CREATE TABLE Images ( PicNum int NOT NULL AUTO_INCREMENT PRIMARY KEY, Image BLOB );
进库:<?php
$Picture=$_POST[file]; //flie是 我那个图片上传页的表单的传递
If($Picture != "none")
{ $PSize = filesize($Picture);
$mysqlPicture = addslashes(fread(fopen($Picture, "r"), $PSize));
mysql_connect("localhost","root","") or die("Unable to connect to SQL server");
@mysql_select_db("mymg") or die("Unable to select database");
mysql_query("INSERT INTO images (image) VALUES ('$mysqlPicture')") or die("Cant Perform Query"); }
else
{ echo"You did not upload any picture"; }
?>
程序到这里都没问题~我用CMD看了下 数据库里也有东西.
输出:
<html>
<body>
<?php
mysql_connect($host,$username,$password) or die("Unable to connect to SQL server");
@mysql_select_db($db) or die("Unable to select database");
$result=mysql_query("SELECT * FROM Images") or die("Cant Perform Query");
While($row=mysql_fetch_object($result))
{ echo "<IMG SRC='Second.php ? PicNum=$row- > PicNum'/>"};! ?>
</body>
</html>
'Second.php:
<?php
$result=mysql_query("SELECT * FROM Images WHERE PicNum=$PicNum") or die("Cant perform Query");
$row=mysql_fetch_object($result);
Header( "Content-type: image/gif");
echo $row->image;
?>