PHP-SQL:上传的图像显示为垃圾文本 [英] PHP-SQL: Uploaded image displaying as junk text

查看:86
本文介绍了PHP-SQL:上传的图像显示为垃圾文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经通过phpMyAdmin将图像和文本直接上传到我的表格。但是,在显示时,图像显示为垃圾文本。可能是什么问题?该图像是一个相对较小的jpg文件。以下是代码:

I've uploaded an image and text directly to my table through phpMyAdmin. However when it comes to displaying, the images are showing up as junk text. What could be the issue? The image is a relatively small jpg file. Here is the code:

<?php
    require_once 'login.php';
    $conn = new mysqli($hn, $un, $pw, $db);
    if($conn->connect_error) die($conn->connect_error);
    $query = "SELECT * from classics";
    $result = $conn->query($query);
    if(!$result) die($conn->error);

    $rows = $result->num_rows;

    for($j=0; $j < $rows; $j++) {
         $result->data_seek($j);
         $row=$result->fetch_array(MYSQLI_ASSOC);
         echo 'Cover:' .$row['sleeve'] .'<br>'; 
    }

    $result->close();
    $conn->close();
?>


推荐答案

像你这样的echo语句应该工作与你当前的实现。

Something like this as your echo statement "should" work with your current implementation.

//echo 'Cover:' .$row['sleeve'] .'<br>'; 
echo '<img src="data:image/jpeg;base64,'.base64_encode( $row['sleeve'] ).'"/>';

但是@Noor是正确的,存储这样的图像效率不高。

However @Noor is correct, storing images like this is not very efficient.

这篇关于PHP-SQL:上传的图像显示为垃圾文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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