如何使用PHP和MySQL在Base64中读取Blob? [英] How to read a blob in Base64 using PHP and MySQL?

查看:244
本文介绍了如何使用PHP和MySQL在Base64中读取Blob?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个有6个月经验的新手,可以通过StackEx/books/etc自学.通过登录/注册创建了一个相当不错的网站,并通过mySQL存储了一些信息.我在这里浏览过每个BLOB帖子,并且得到了不错的输出.

I am a newb with 6 months experience, self-taught via StackEx/books/etc. Created a pretty decent website with login/register and storing some info via mySQL. I have been through every single BLOB post here and I have some decent output.

我想我像大多数新手一样,足够了解危险,没有最深厚的基础,因此当认真了解内置函数,数组和传递参数时,我们可能会迷失方向.基本上认为我已经通过使用include调用了一些导航栏来挖了一个洞,因此我不能仅使用标头来输出该死的图像,因为我在登录后回显了用户名,因此它已经输出了行,对于撤消.导航,未认证,已认证和管理员三个级别.

I think I, like most newbs, know enough to be dangerous, don't have the greatest foundation laid out so when it gets to serious understanding of built-in functions, arrays and passing arguments we can lose the flow and I basically think I have dug a hole by using includes to call some navbar so that I can't just use a header to output the damn image as I echo the user name after login so it has already outputted lines and it will be a monster to undo. Three levels of nav, unauthenticated, authenticated and admin.

数据库连接和写入/读取均可以.我可以存储BLOB,甚至可以读回BLOB并将其存储在变量中,然后调试以查看二进制文件,但是我无法使其显示在HTML页面上.

The database connection and write to/read from is OK. I can store the BLOB and I can even read it back and store the array in a variable and then debug see the binary but I can't get it to display on an HTML page.

这很有趣:

$stmt = $dbc2->query("SELECT * FROM equip1");

while ($row = $stmt->fetch(PDO::FETCH_ASSOC))
{
$name = $row['equipname1'];
$desc = $row['equipdesc1'];
$img = $row['equipimg1'];
}

<div class="col-lg-12">
    <h1><?php echo $name ?></h1>
    <p><?php echo $desc ?></p>
    <pre>
        <?php print_r($img); ?>
    </pre>
    <?php echo "<img src='data:image/jpeg;base64," . base64_encode( $img ) . "' />"; ?>
</div>

$ dbc2连接 equip1表是两个简单的varchar cols,一个BLOB col. $ name和$ desc回显确定,$ img显示断开的链接. 我通过预编码检查数组,并根据上传过程中以dB为单位存储的内容进行匹配. 从我阅读和遍历的内容来看,除非通过我已经完成但仍然断开的数据URI,否则您似乎无法同时进行此操作.对我完全没有意义.我尝试使用标头,当然已经开始输出,但是我也可以看到输出二进制文件.

$dbc2 connects equip1 table is two simple varchar cols, one BLOB col. $name and $desc echo out ok, the $img displays broken link. I check the array via pre code and is matching, per what is stored in dB during upload. From what I have read and gone through, seems like you can't do this at same time unless via data URI which I have done but still broken link. Not making sense to me at all. I try the header and of course output already started but I can see also outputs the binary.

这是URI方法的屏幕截图:

Here is screenshot of the URI method:

由于这两种方法似乎"都能进入和退出dB,但没有显示,所以我正在绕圈转.请帮助我在html页面上显示图像.我想在任何地方回显它,然后在此之后对页面进行样式设置.谢谢!

Since both methods "seem" to get into and out of the dB but do not display I'm going round in circles. Please help me out to display the image on an html page. I would like to echo it anywhere and then I can just style the page after that. Thanks!

推荐答案

像这样尝试

<?php echo '<img src="data:image/png;base64,'.base64_encode($img).'">';?>

这篇关于如何使用PHP和MySQL在Base64中读取Blob?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆