[英]unable to display images in a grid using php html
我使用本網站的代碼來顯示目錄中的圖像及其文件名。 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>
我在控制台中收到這個有趣的錯誤:-
<a href=".$dirname .$curimg."><img src=".$dirname .$curimg."></a>
圖像未顯示(我只能看到損壞的圖像圖標),當我單擊它時,我看到這個http://192.168.1.7/temp/.$dirname%20.$curimg.
試試這個,這里我只是簡化了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>
這是工作圖像
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.