引导映像行不合适


bootstrap image row out of place

[已解决]

我使用占位符写了一行水平的 4 张 500x300 图像,这工作得很好,但是当我尝试用相同尺寸的文件夹(使用 php)中的图像替换这些图像时,前 2 个图像包含被淘汰,而最后 2 个是它们所属的地方。我附上了屏幕截图,下面的代码是我用来获取图像行的代码。

<div class="row" style="margin-top:1px">
<?php
$directory = 'images';
if (! is_dir($directory)) {
exit('Invalid diretory path');
}
$files = array();
foreach (scandir($directory) as $file) {
?>
<div class="col-sm-3 col-xs-6" >
<a href="#" >
<img  class="img-responsive portfolio-item" src="<?php echo "images/$file"; ?>" alt="">
</a>
</div>
<?php
}
?>
</div>

这是我在浏览器中得到的

使用 glob 而不是数组解决了这个问题。PHP 包括 .和目录结构的双点,因此创建 2 个空图像。