如何使用PHP显示存储在mysql数据库中的图像

编程入门 行业动态 更新时间:2024-10-25 08:21:45
本文介绍了如何使用PHP显示存储在mysql数据库中的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我一直试图使用php显示数据库中的图像,但是每当我使用或单击链接时,我只会得到下载提示.我想做的是,我想在网络浏览器上显示它.并想在标签中使用它.

I have been trying to display image from database using php but i am only getting download prompt whenever i use or click the link. what i want to do is, i want to display it on the web browser. And want to use it in tags.

我的代码是:

require_once('dbconfig.php'); $cont=mysql_connect($dbhost,$dbuser,$dbpass) or die("Error Connecting the Database"); $seldatabase=mysql_select_db($dbselect,$cont); $insert = "SELECT `p_mime`, `p_name`, `p_size`, `p_data` FROM $dbtbl_reg_details WHERE `id` = $id"; $query = mysql_query($insert); if ($query) { if (mysql_num_rows($query)==1) { $row = mysql_fetch_assoc($query); header("Content-Type: image/png"); header("Content-Length: ". $row['p_size']); header("Content-Disposition: inline; filename=". $row['p_name']); echo $row[p_data]; } else { echo "image with id = ".$id." does not exist"; } } else { echo "query failed, image with id = ".$id." does not exist"; }

当我使用内联进行内容处置时:然后我的网页在浏览器中返回了脚本错误.

And when i use inline for Content-Disposition: then my web page returns a script error on the browser.

因此,当我从mysql数据库中检索图像时,我应该怎么做才能在网页上显示图像

So, what should i do to display images on web pages while retrieving it from mysql database

推荐答案

if (mysql_num_rows($query)==1) { while( @ob_end_clean() ); header("Content-type: image/png"); header("Content-Length: ". $row['p_size']); header("Content-Disposition: attachment; filename=\"{$row['p_name']}\""); die($row[p_data]); }

更多推荐

如何使用PHP显示存储在mysql数据库中的图像

本文发布于:2023-11-27 20:18:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1639459.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据库中   如何使用   图像   mysql   PHP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!