为什么PHP无法显示照片

来源:百度知道 编辑:UC知道 时间:2024/06/06 00:10:04
这是我的代码
上传到数据库里已经没有问题了,只是在显示照片的时候显示乱码,下面是显示照片的代码
$dbh=new pdo("mysql:host=localhost;port=3306;dbname=second","root","");
$dbh->exec("set character set gb2312");
$result=$dbh->query("select * from four where name= 'can' ");
$row=$result->fetch();
if(!empty($row)){
header ("content-type: image/JPEG",true);
?>
<table>
<tr>
<td width="100" height="100">
<?php
echo ($row["pic"]);
}
?>

你的网页上设置的输出格式为:JPEG 下面又还有表格的信息,貌似有问题吧。

你这没有照片的地址啊,只是输出照片的名字而已

你应该这样写:
首先写一个1.php,相关部分内容是
<table>
<tr>
<td width="100" height="100">
<img src="2.php">

然后写一个2.php,内容大致是:
<?php
$dbh=new pdo("mysql:host=localhost;port=3306;dbname=second","root","");
$dbh->exec("set character set gb2312");
$result=$dbh->query("select * from four where name= 'can' ");
$row=$result->fetch();
if(!empty($row)){
header ("content-type: image/JPEG",true);
echo ($row["pic"]);

}
?>