doujiao0110 2014-07-23 12:15
浏览 30

使用PHP获取文件夹图像显示额外的空白

I'm using php to get & display the images in a folder and everything has been working fine until I added the NEW images to the folder - It's now adding a blank space before the first gallery image. When I echo out the $count it shows that there are 8 files instead of the 7 that there actually are. What is the reason for this and how can I prevent it?

My PHP code is:

<div id="gallery">
    <h1>Take A Look Around:</h1>
    <p>
        <?php

        $folder = 'gallery/';
        $filetype = '*.*';
        $files = glob($folder.$filetype);
        $count = count($files);
        for ($i = ($count-1); $i >= 0; $i--) {
            echo '<div class="photoHolder"><div class="photoCell"><a class="fancybox" rel="group" href="'.$files[$i].'"><img class="photo" src="'.$files[$i].'" alt=""></a></div></div>';
        }
        ?>
    <div class="clearLeft"></div><?php echo $count; ?>
    </p>
</div>
  • 写回答

2条回答 默认 最新

  • dqr3883 2014-07-23 12:17
    关注

    This code should work

    <div id="gallery">
        <h1>Take A Look Around:</h1>
        <p><?php
    
            $folder = 'gallery/';
            $filetype = '*.*';
            $files = glob($folder.$filetype);
            foreach ($files as $file)
            {
                echo '<div class="photoHolder"><div class="photoCell"><a class="fancybox" rel="group" href="'.$file.'"><img class="photo" src="'.$file.'" alt=""></a></div></div>';
            }
            ?></p>
        <div class="clearLeft"></div>
        <p><?php echo count($files); ?></p>
    </div>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计