drux41001 2012-06-26 18:08
浏览 61
已采纳

PHP分页:is_dir在循环读取readdir时截断图像

I just got pagination to work on my site, but I wanted to use a thumbnailer script that accepts a path, not a resource. This conflicts with how I pagination- using readdir to scan for a resource.

Right now I'm implementing a skip pattern I found online to keep track of images and their corresponding page numbers:

while ( $count <= $skip && ($file = readdir($handle)) !== false ) {
            if ( !is_dir($file))
                $count++;
        }

        $count = 0;

So,

Question 1) This method sets $count = 0 after it's run, so I don't see how it can be useful for the rest of the script.

Question 2) This part actually displays the correct images on page according to page number. I set $imagesPerPage = 4, so 4 should display on all pages. But, since I'm doing an !is_dir check, it's truncating those first two items (which are directories . and ..), but it's not refilling those spots with actual images (bec all pages except the last page should have 4 images on them...)

while ( $count++ < $imagesPerPage && ($file = readdir($handle)) !== false ) {
            if(!is_dir($file)) {
            $image = $imagePath . $file;
        ?>
            <a href="../templates/viewComic.php?image=<?php echo $image ?>"><img src="../scripts/thumbnailer2.php?img=<?php echo $image ?>" /></a>  

        <?php
            }   
        }

enter image description here

Question 3) How can I get the pages to begin on 1 instead of 0?

Any help in understanding would be appreciated!

  • 写回答

1条回答 默认 最新

  • doudou32012 2012-06-26 18:43
    关注

    1) This is resetting $count to 0 when the While is done with it.

    2) You only want to increment $count if it's not a directory. You should put it inside the if(!is_dir($file)) section.

    3) Initialize $count as 1 instead of 0.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog