如何在SQL查询的Session变量中插入图像?

时间:2018-11-24 13:33:36

标签: php sql image session

您好,我正在尝试在sql登录查询中启动会话 将图像保存在Session变量中并显示。如何在SQL查询的Session变量中插入图像?

查询:

    function checkuser($conexionBd,$us,$pass){

            $sentence= $conexionBd->prepare("SELECT us_id, us_img FROM users where us_us=? AND us_pass=?");
            $img='us_img';
            session_start();
        $sentence->execute(array($us, $pass));
            if ($sentence->rowCount()==1) {

            $_SESSION['img']= $img;

            header("Location:img.php");
            exit();
            }else{

            echo 'user or password incorrect';
            }

            }

1 个答案:

答案 0 :(得分:0)

您首先需要加载图像并使用base64对其进行转换。

[30, 63, 63, 7, 62, 79, 1, 54, 20, 45, 93, 45, 38, 30, 84, 64].

然后将$ base64变量添加到会话中

$path = 'myfolder/myimage.png';
$type = pathinfo($path, PATHINFO_EXTENSION);
$data = file_get_contents($path);
$base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
相关问题