如何在sql查询中的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';
}
}

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

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

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

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

最新更新