[英]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.