无法在 PHP 中显示图像
这是我的图像显示代码 -
$username = "xxxxxxxx";
$password = "xxxxxxxx";
$host = "000.001.000.000";
$database = "xxxxxxxx";
@mysql_connect($host, $username, $password) or die("Can not connect to database: ".mysql_error());
@mysql_select_db($database) or die("Can not select the database: ".mysql_error());
$query = mysql_query("SELECT mimetype, Image FROM table ORDER BY id DESC LIMIT 0,1");
$row = mysql_fetch_array($query);
$content = $row['Image'];
header('Content-type: image/jpg');
echo $content;
这是我收到的错误
图像“http://www....”无法显示,因为它包含错误。
怎么了? mysql中字段的数据类型是mediumblob
here's my code for image display -
$username = "xxxxxxxx";
$password = "xxxxxxxx";
$host = "000.001.000.000";
$database = "xxxxxxxx";
@mysql_connect($host, $username, $password) or die("Can not connect to database: ".mysql_error());
@mysql_select_db($database) or die("Can not select the database: ".mysql_error());
$query = mysql_query("SELECT mimetype, Image FROM table ORDER BY id DESC LIMIT 0,1");
$row = mysql_fetch_array($query);
$content = $row['Image'];
header('Content-type: image/jpg');
echo $content;
This is the error i'm getting
The image “http://www....” cannot be displayed because it contains errors.
what is wrong? The datatype of field in mysql is mediumblob
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好的,首先测试一下,看看发生了什么:
这应该显示数据库的结果,或者错误消息。如果您看到错误消息,请更正导致该错误的任何原因...
在上面仅返回数据库行内容之后:(
假设
mimetype
字段类似于“image/jpg”)OK, first test, to see what is happening:
That should either show you the results from the database, or an error message. If you see an error message, correct whatever is causing it...
After the above just returns the Database row contents:
(assuming that the
mimetype
field is something like "image/jpg")我建议在输出之前添加内容长度标头:
I'd suggest adding a content-length header before your output:
我建议更改标头以使其动态取决于图像 mime 类型:
I'd suggest to change the header to make it dynamic depend on the image mime-type: