[英]unable to display images in a grid using php html
Im using the code from this website to display images from a directory along with their file name.我使用本网站的代码来显示目录中的图像及其文件名。 https://github.com/dcblogdev/gallery-from-folder https://github.com/dcblogdev/gallery-from-folder
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Gallery from Folder Demo</title>
<style type="text/css">
<!--
li{
list-style-type:none;
margin-right:10px;
margin-bottom:10px;
float:left;
}
-->
</style>
</head>
<body>
<ul>
<?php
$dirname = "images/";
$images = scandir($dirname);
shuffle($images);
$ignore = Array(".", "..");
foreach($images as $curimg){
if(!in_array($curimg, $ignore)) {
echo "<li><a href='".$dirname.$curimg."'><img src='img.php?src=".$dirname.$curimg."&w=300&zc=1' alt='' /></a></li>\n";
}
}
?>
</ul>
</body>
</html>
Im getting this funny error in console: -我在控制台中收到这个有趣的错误:-
<a href=".$dirname .$curimg."><img src=".$dirname .$curimg."></a>
Image isnt showing up (I can only see a broken image icon), when I click on it I see this http://192.168.1.7/temp/.$dirname%20.$curimg.
图像未显示(我只能看到损坏的图像图标),当我单击它时,我看到这个http://192.168.1.7/temp/.$dirname%20.$curimg.
try out this, here I just simplified the echo of li
code, and you no need \n
at the end of the list tag, coz as per HTML li
after completion of one li
tag it moves to the next line by default试试这个,这里我只是简化了li
代码的回显,你不需要\n
在列表标签的末尾,因为按照 HTML li
在完成一个li
标签后它默认移动到下一行
<ul>
<?php
$dirname = "images/";
$images = scandir($dirname);
shuffle($images);
$ignore = array(".", "..");
foreach($images as $curimg){
if(!in_array($curimg, $ignore)) {
echo '<li><a href="'.$dirname.$curimg.'"><img src="'.$dirname.$curimg.'"></a></li>';
}
}
?>
</ul>
here is the working Image这是工作图像
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.