[英]Retrieve Image from database, display and attach it to a link
I have Images stored in my DB, I want to retrieve them all and display them in the browser. 我的数据库中存储有图像,我想全部检索它们并在浏览器中显示它们。 It works just fine, but I want to give the user the ability to click on the picture so that they can have a better view of the picture (so display it with its original size).
效果很好,但我想让用户能够单击图片,以便他们可以更好地查看图片(因此以原始尺寸显示它)。 I tried many things but didn't work.
我尝试了很多事情,但没有成功。 second question: if I want my code to support multiple images type (such gif, jpg, etc..), if there a way to do it without having to save the image type (when I insert the images) and play with a whole bunch of if/else (when I retrieve them)?
第二个问题:如果我想让我的代码支持多种图像类型(例如gif,jpg等),是否有一种无需保存图像类型的方法(当我插入图像时)并整体播放一堆if / else(当我检索它们时)?
This is my code 这是我的代码
$count = 0;
echo " <div class=\"row\">";
while($row = $result->fetch_assoc()) {
$imagename = base64_encode( $row['Image'] );
if(($count%3) ==0){
echo "</div>";
echo " <div class=\"row\">";
echo " <div class=\"col-sm-2\">";
echo " <a href=\"$imagename.jpeg\" class=\"thumbnail\">";
echo '<img src="data:image/jpeg;base64,'.base64_encode( $row['Image'] ).'" style=\"width:130px;height:130px\"/>';
echo"</a></div>";
++$count;
}else{
echo " <div class=\"col-sm-2\">";
echo " <a href=\"$imagename.jpeg\" class=\"thumbnail\">";
echo '<img src="data:image/jpeg;base64,'.base64_encode( $row['Image'] ).'" style=\"width:130px;height:130px\"/>';
echo"</a></div>";
++$count;
}
}
echo "</div>" ;
The answer to your first question is "You have to use light-box jQuery plugin", in order to display larger (original size) of a thumbnail you need to use any lightbox plugin, I recommend using this one http://www.jqueryscript.net/zoom/Responsive-jQuery-Lightbox-Like-Image-Zooming-Plugin-Lighter.html Or you can search for any other plugin, there are thousands of them. 第一个问题的答案是“您必须使用灯箱jQuery插件”,为了显示更大(原始尺寸)的缩略图,您需要使用任何灯箱插件,我建议您使用一个http:// www。 jqueryscript.net/zoom/Responsive-jQuery-Lightbox-Like-Image-Zooming-Plugin-Lighter.html或您可以搜索任何其他插件,其中有成千上万个。
Regarding your second question, If you will use data as an images source, you have to specify a type, no way you can do that without mentioning types. 关于第二个问题,如果要将数据用作图像源,则必须指定一种类型,没有提及类型就无法做到这一点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.