我有一个php页面,其中包含来自数据库的blob
在没有斑点的情况下,我需要显示404图像
https://i.imgur.com/gp0Q2kQ.jpg https://i.imgur.com/XgGDExK.jpg
<?php
$host = "localhost";
$username = "root";
$password = "12345678";
$db = "sis";
$PicNum = $_GET["PicNum"];
mysql_connect($host,$username,$password) or die("Impossível conectar ao banco.");
@mysql_select_db($db) or die("Impossível conectar ao banco.");
$result=mysql_query("SELECT * FROM usuarios WHERE id=$PicNum") or die("Impossível executar a query ");
$row=mysql_fetch_object($result);
Header("Content-type: image/gif");
echo $row->avatar;?>
答案 0 :(得分:-1)
检查查询中的blob列是否为empty or NULL
。
$result = mysql_query("SELECT * FROM usuarios WHERE id=$PicNum AND WHERE length(avatar) != 0 AND avatar IS NOT NULL") or die("Impossível executar a query ");
$row=mysql_fetch_object($result);
if($row)
echo $row->avatar;
else
{
// return 404 page or print as 404 error
"<h1>404 Not Found</h1>";
echo "The page that you have requested could not be found.";
}
?>