这是我用php写的,可以将图片存到数据库里。可以在网页上显示出来
上传
<?
unset($level);
include("amusement/session.inc");
if($level!="admin"){
echo "您无此权限";
exit();
}
$db_name='film';
include("con_db.inc");
if($file_data_name!=""){
//先将图片存入数据库以便得到image_id,与mp3表产生关联
$data=addslashes(fread(fopen($file_data,"r"),filesize($file_data)));
$str_sql= "insert into bin_data
(
data,
name,
type,
size
)
values
(
'$data',
'$file_data_name',
'$file_data_type',
'$file_data_size'
)";
if(!$result = mysql_db_query ($db_name,$str_sql,$link_id)){
echo "插入图像失败";
echo mysql_errno().": ".mysql_error()."<br>";
exit();
}
$image_id= mysql_insert_id();
//echo "图象已经添加到数据库(id:$image_id)";
}
else
{
echo "请选择文件";
exit();
}
Header("Location: index.php?mode=list_all_pic&page_no=0");
?>
显示:
<?
$db_name='film';
include("con_db.inc");
$image_id=$HTTP_GET_VARS[image_id];
$str_sql="select * from bin_data where id=$image_id";
if($result = mysql_db_query ($db_name,$str_sql,$link_id)){
if($row = mysql_fetch_object($result)){
Header( "Content-type: $row->type");//注意这儿
echo $row->data;
}
}
else
{
//echo mysql_errno().": ".mysql_error()."<br>";
}