【发布时间】:2012-02-03 12:46:35
【问题描述】:
我目前有一个数据库,我可以在其中存储图像..
但是我为显示它们而创建的 PHP 页面......不起作用。
但是,当我将链接用作 的 scr 时,它会显示一个空的图像帧。
如果我直接回显图像,我会得到很多奇怪的迹象
我想要显示图像的方式是:
我用于显示图像的代码(image.php)是:
<?php session_start();
if(!isset($_GET['image']))
{
header("HTTP/1.0 404 Not Found");
}
else{
$link = mysql_connect('localhost', '45345345435435345', 'wewfsersdfds');
if (!$link) {
echo "error";
die;
}
$db_selected = mysql_select_db(Tha base, $link);
if (!$db_selected) {
echo "error";
die;
}
$nummer=(int)trim(stripslashes($_GET['image']));
$mynr=$nummer;
$sql="SELECT * FROM Foto WHERE fotonr=$mynr";
$result=mysql_query($sql);
if(!$result)
{
echo "error".mysql_error();
header("HTTP/1.0 404 Not Found");
}
else
{
$foto = mysql_fetch_assoc($result);
header("Content-type: ".$foto['type']);
echo $foto['image'];
}
}
?>
我已经尝试了很多,但它不会工作:( 我将代码更新到最新版本。 sql出错(什么都不选/从不做一个int的mysql_real_escape_string)
现在它显示的是直线字符,而不是图像,这至少是一个改进......
有人可以帮我吗?
感谢您的宝贵时间!
【问题讨论】:
-
为什么要将图像存储在数据库中?将文件存储在文件系统中并引用该文件在数据库中的路径不是更有意义吗?