所以我正在尝试合并 LightBox 插件以便弹出图像:LightBox Info
但是我的 php 代码代码使用 img
标签而不是 Lightbox 要求的 a
标签。尝试时似乎 href 和 src 冲突。图像和所有内容都正确显示,这只是在我的代码中使用 LightBox 的问题。我想知道是否有人知道该怎么做。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script src="/var/www/html/jquery-1.11.3.min.js"></script>
<script src="/var/www/lightbox2-master/dist/js/lightbox.js"></script>
<title>Greeting Cards</title>
<link rel="icon" type="image/png" href="../../favicon-32x32.png" sizes="32x32" />
<link rel="icon" type="image/png" href="../../favicon-16x16.png" sizes="16x16" />
<link rel="icon" type="image/x-icon" href="../../chromevers.ico" />
<link rel="stylesheet" type="text/css" href="../../styles/catbar.css">
<link rel="stylesheet" href="/var/www/lightbox2-master/dist/css/lightbox.css">
</head>
<body>
<?php
include '/var/db_file.php';
include '/var/www/WideImage/lib/WideImage.php';
$con = mysqli_connect($theDb,$usr, $pass, "images");
mysqli_select_db($con, "images");
$query = "SELECT * FROM Greeting_Cards";
$result = mysqli_query($con, $query);
$images = array();
while($row = mysqli_fetch_assoc($result)){
$images[] = $row['image'];
}
echo '<div id ="gallery">';
foreach ($images as $image) {
$image = WideImage::loadFromString($image)->resize(300, 300);
echo '<img id="database" src="data:image/jpeg;base64,'. base64_encode($image) .'" />';
}
echo '</div>';
mysqli_close($con);
?>
</body>
</html>
谢谢!
最佳答案
我设法以另一种方式显示我的图像。我将图像上传到服务器并将图像路径存储在数据库中。这种方式将使您的网站更快,因为您不会为大量图像提取 BLOB,而只会在您的服务器上引用它们。这是代码行:
echo '<a href="'. $image.'" data-lightbox="roadtrip"><img id="dbImages" src="data:image/jpg;base64,'.base64_encode($reimage).'"/></a>';
$image
变量是 $row = mysqli_fetch_assoc()
调用存储图像路径。和 $reimage
正在使用 php 库 WideImage
从路径加载图像。该库还有许多其他非常有用的图像处理函数供您使用。希望这对您有所帮助!
关于php - jquery - 使用 Lightbox 插件和来自 mysql 数据库的 blob,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31472926/