简体   繁体   English

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

[英]How can I insert an image into a Session variable in sql query?

hello I'm trying to start a session in the sql login query to save the image in a Session variable and display it. 你好,我试图在sql登录查询中启动一个会话,以将图像保存在Session变量中并显示它。 How can I insert an image into a Session variable in sql query? 如何在SQL查询的Session变量中插入图像?

Query: 查询:

    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';
            }

            }

You first need to load your image and convert it using base64. 您首先需要加载图像并使用base64进行转换。

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

Then you add $base64 variable to session 然后将$ base64变量添加到会话中

session_start();
$_SESSION['product_number'.$base64 ] = true;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM