谢谢你的帮助。我在显示从我的数据库中检索图像时遇到问题。
在img src中加载image.php或直接从页面加载时无法看到图像。当我显示没有header('Content-type: image/jpeg');
的变量时,我可以看到里面的所有代码,因为我把这一行全部消失了。
我有一个名为TABLE的表,其中id,title,img存储为longblob直接上传到phpmyadmin内。
任何人都可以帮助我吗?
index.php
<?php
session_start();
include "admin/include/connection2.php";
$data = new MysqlClass();
$data->connect();
$query_img ="SELECT * FROM table ORDER BY data ASC LIMIT 4";
$post_sql = $data->query($query_img);
if(mysql_num_rows($post_sql) > 0){
while($post_obj = $data->estrai($post_sql)){
$id = $post_obj->id;
$titolo = stripslashes($post_obj->title);
$data_articolo = $post_obj->data;
$immagine = $post_obj->img;
// visualizzazione dei dati
echo "<h2>".$titolo."</h2>";
echo "Autore <b>". $autore . "</b>";
echo "<br />";
echo '<'.'img src="image.php?id='.$post_sql['id'].'">';
echo $id;
echo "<hr>";
}
}else{
echo "no post aviable.";
}
// here is the image.php code
<?php
include "admin/include/connection2.php";
$data = new MysqlClass();
// connect
$data->connetti();
$id = $_GET['id'];
echo $id;
$query = mysql_query("SELECT * FROM articoli_news WHERE id='".$id."'"; //even tried to send id='1' but not working
echo $query;
$row = mysql_fetch_array($query);
echo $row['id']; //correct displaying
$content = base64_decode($query['img']);
header('Content-type: image/jpeg');
echo $content;
?>
答案 0 :(得分:0)
删除除“echo $ content;”之外的所有“echo”命令因为输出中也会出现,并损坏你的图像。 并使用ob_start();在脚本的开头,检查你的脚本文件在php begint和close标签之前或之后不包含任何空白字符。