php+mysql显示不出图片,这是为什么

Nothing_two 2017-11-20 09:17:37
--- index.php

<?php
include('conn.php');
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equive="Content-Type" content=text/html charset=utf-8>
<title> </title>
</head>
<body>
<form method='post' action='upload.php' enctype="multipart/form-data">
<input type="file" name="image" />
<input type="submit" name="submit" value="上传" />
</form>

<!-----------显示图片--------------------->

<table>
<?php
$ret = @mysql_query('select * from image order by id desc');
if ($ret) {
while ($row = mysql_fetch_array($ret)) {
?>
<tr>
<td style='width:170px;'>
<img src="image.php?id=<?php
echo $row[id];
?>" width="170" height="150" border="0">
<div style='text-align:center;'><?php
echo $row['name'];
?></div>
<?php
echo $row['date'];
?>
</td>
</tr>
<?php
}
}
?>
</table>
<!-----------/显示图片--------------------->
</body>
</html>

--- image.php
<?php
include('conn.php');

$id = $_GET['id'];
$sql = "select * from image where id='$id'";
$result = @mysql_query($sql, $conn);
if (!$result)

die("读取图片失败!");
$num = mysql_num_rows($result);
$num = mysql_affected_rows($result);
if ($num < 1)
die("暂无图片");
$data = mysql_result($result, 0, 'pic');
$type = mysql_result($result, 0, 'type');
mysql_close($id);
echo alert(mysql_close($id));
Header("Content-type: $type");
echo $data;
?>

--- upload.php
<?php
include('conn.php');
if ($_POST['submit']) {
if ($_FILES['image']['size']) {
$names = $_FILES['image']['name'];
$arr = explode('.', $names);
$name = $arr[0]; //图片名称
$date = date('Y-m-d H:i:s'); //上传日期
$fp = fopen($_FILES['image']['tmp_name'], 'rb');
$type = $_FILES['image']['type'];
if (!$fp) {
showInfo('读取图片失败!');
} else {
$image = addslashes(fread($fp, filesize($_FILES['image']['tmp_name'])));
if ($image) {
$q = "insert into image (name, pic, type, date) values ('$name','$image','$type','$date')";
$result = @mysql_query($q);
if ($result) {
showInfo('上传成功!');
} else {
showInfo('上传失败!');
}

} else {
showInfo('请选择要上传的文件!');
}
}

} else {
showInfo('请选择要上传的文件!');
}
}


function showInfo($info)
{
echo "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />";
echo "<meta http-equiv='refresh' content='1;url=index_tp.php'>";
echo "</head>";
echo "<body>" . $info . "……</body>";
echo "</html>";
}
?>


就是不显示图片,求大神指导



...全文
360 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
一起混吧 2017-11-23
  • 打赏
  • 举报
回复
你的image.php 需要接收id值,而看你#5的代码没有看到传递id值过去。
youyiyang 2017-11-23
  • 打赏
  • 举报
回复
html img src=后面一般是图片的路径,如果像你用image.php我还没有碰到过
码无边 2017-11-22
  • 打赏
  • 举报
回复
image.php是啥?
szuzsq 2017-11-21
  • 打赏
  • 举报
回复
为毛phper不爱调试呢?设个断点,一步一步next执行代码.巨爽. 可以看看xdebug
hongmei85 2017-11-21
  • 打赏
  • 举报
回复
去掉$num = mysql_affected_rows($result);试试
Nothing_two 2017-11-21
  • 打赏
  • 举报
回复




说因存在错误,无法显示
Nothing_two 2017-11-21
  • 打赏
  • 举报
回复
现在显示的是全黑的,这是什么回事,求大神
Nothing_two 2017-11-21
  • 打赏
  • 举报
回复

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧