[英]How can I insert an image into a Session variable in sql query?
你好,我试图在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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.