各位大侠好!
请教下如何显示存入mysql表blob类型字段的图片?
我用的代码: Header( "Content-type: image/gif");
$sql='select imag from tablename where id=1';
$rst= $conn->execute($sql);
echo $rst['img'];存入时代码:
$fileinfo=$_FILES['attfile'];
$file_name = $fileinfo['name'];
$file_newname=$fileinfo['tmp_name'];
$temp_a=fread(fopen($file_newname,"r"),filesize($file_newname));
$filecontent=addslashes($temp_a);
$sql='insert into tablename(img) values('.$filecontent.')';
$rst=$conn->execute($sql);
我没有分数可给,对不起啊。比较急。
请教下如何显示存入mysql表blob类型字段的图片?
我用的代码: Header( "Content-type: image/gif");
$sql='select imag from tablename where id=1';
$rst= $conn->execute($sql);
echo $rst['img'];存入时代码:
$fileinfo=$_FILES['attfile'];
$file_name = $fileinfo['name'];
$file_newname=$fileinfo['tmp_name'];
$temp_a=fread(fopen($file_newname,"r"),filesize($file_newname));
$filecontent=addslashes($temp_a);
$sql='insert into tablename(img) values('.$filecontent.')';
$rst=$conn->execute($sql);
我没有分数可给,对不起啊。比较急。
解决方案 »
- 关于建立专家Twitter社区的一种想法
- 关于DISCUZ中的这个变量$cachelost
- 我做的zen cart到了第二页就不会显示脚页了 为什么?怎么做
- 这是什么错误?
- 哪位好心人给推荐几个下载PHP源码的网站
- 有没有类似my97datepicker的treeview插件啊
- 递归处理数组的问题请教
- wordpress的thumbnail文章列表缩略图函数如何设定
- 想做个网址导航,请问这种风格的导航是用的什么模板?有现成的CMS吗?
- php下rabbitmq怎么实现消费者自动触发
- 大家说说PHP开源软件中最复杂的系统
- ******正在做个PHP平台,如何保存最后一次记录?blob******
$sql='select imag from tablename where id=1';
$rst= $conn->execute($sql);
$im = imagecreatefromstring($rst['img']);
if($im != false){
Header( "Content-type: image/gif");
imagegif($im);
imagedestroy($im);
}else{
echo 'An error occurred.';
}
?>
$sql='select imag from tablename where id=1';
$rst= $conn->execute($sql);
$im = imagecreatefromstring(stripslashes($rst['img']));
if($im != false){
Header( "Content-type: image/gif");
imagegif($im);
imagedestroy($im);
}else{
echo 'An error occurred.';
}
?>
怎么处理啊?
<?php
session_start();
include_once 'conn/conn.php';
$strId=$_GET['ID']; //记录ID
$strTb=$_GET['TB']; //表名称
$strGraphFn=$_GET['GRAPHNAME']; //图片字段名称
$strIdFn=$_GET['KEYNAME']; //KEY字段名称
$sql='select '.$strGraphFn.' from '.$strTb.' where '.$strIdFn.'='.$strId;
$temp_graph_content= $conn->execute($sql);
if(!($temp_graph_content==null || $temp_graph_content->RecordCount()==0))
{
$temp_img=imagecreatefromstring(stripslashes($temp_graph_content[$strGraphFn]));
if ($temp_img!=false)
{
Header( "Content-type: image/gif");
imagegif($temp_img);
imagedestroy($temp_img);
}else
{
echo 'An error occurred.';
}
}else
{
echo "";
}
?>
1)确认你能从数据库中正确查询出数据2)将数据转为图片,JPEG格式的要用
Header( "Content-type: image/jpeg");
imagejpeg($temp_img);
报错依旧,2种类型图片全试验过了。
直接插入$temp_a试试