Folder list with Pagination

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jerryyang_la1@yahoo.com

    Folder list with Pagination

    I'm looing for a simple PHP file list program, that will show all the
    files in a folder, but show them in batchs of 10 - 15..

    Any ideas??

    Many Thanks

  • Noodle

    #2
    Re: Folder list with Pagination


    jerryyang_la1@y ahoo.com wrote:
    I'm looing for a simple PHP file list program, that will show all the
    files in a folder, but show them in batchs of 10 - 15..
    >
    Any ideas??
    >
    Many Thanks
    This is a little crude but it should get the job done.

    <?php
    if ($handle = opendir('.')) {
    $count = 0;
    while (false !== ($file = readdir($handle ))) {
    echo $count == 0 ? "<ol>" : "";
    echo "<li>$file</li>";
    $count++;
    if($count == 10){
    echo "</ol>";
    $count = 0;
    }
    }
    echo $count != 10 ? "</ol>" : "";
    closedir($handl e);
    } ?>

    Comment

    • Noodle

      #3
      Re: Folder list with Pagination


      jerryyang_la1@y ahoo.com wrote:
      I'm looing for a simple PHP file list program, that will show all the
      files in a folder, but show them in batchs of 10 - 15..
      >
      Any ideas??
      >
      Many Thanks
      Another solution would be to read the file names into an array and
      iterate over that in sets of 10 or 15.

      Comment

      • jerryyang_la1@yahoo.com

        #4
        Re: Folder list with Pagination


        Noodle wrote:
        jerryyang_la1@y ahoo.com wrote:
        I'm looing for a simple PHP file list program, that will show all the
        files in a folder, but show them in batchs of 10 - 15..

        Any ideas??

        Many Thanks
        >
        This is a little crude but it should get the job done.
        >
        <?php
        if ($handle = opendir('.')) {
        $count = 0;
        while (false !== ($file = readdir($handle ))) {
        echo $count == 0 ? "<ol>" : "";
        echo "<li>$file</li>";
        $count++;
        if($count == 10){
        echo "</ol>";
        $count = 0;
        }
        }
        echo $count != 10 ? "</ol>" : "";
        closedir($handl e);
        } ?>
        Hi

        Thanks for that..It works, but I didn't describe it properly...

        What I should have said that I would like it to use pagination, showing
        10 entried per page, then allowing the user to move back or forward
        through the pages !

        Cheers

        Comment

        • Sandman

          #5
          Re: Folder list with Pagination

          In article <1158137962.446 398.40570@d34g2 000cwd.googlegr oups.com>,
          jerryyang_la1@y ahoo.com wrote:
          Noodle wrote:
          jerryyang_la1@y ahoo.com wrote:
          I'm looing for a simple PHP file list program, that will show all the
          files in a folder, but show them in batchs of 10 - 15..
          >
          Any ideas??
          >
          Many Thanks
          This is a little crude but it should get the job done.

          <?php
          if ($handle = opendir('.')) {
          $count = 0;
          while (false !== ($file = readdir($handle ))) {
          echo $count == 0 ? "<ol>" : "";
          echo "<li>$file</li>";
          $count++;
          if($count == 10){
          echo "</ol>";
          $count = 0;
          }
          }
          echo $count != 10 ? "</ol>" : "";
          closedir($handl e);
          } ?>
          >
          Hi
          >
          Thanks for that..It works, but I didn't describe it properly...
          >
          What I should have said that I would like it to use pagination, showing
          10 entried per page, then allowing the user to move back or forward
          through the pages !
          >
          Cheers

          #!/usr/bin/php
          <?
          if (!$_GET["start"]) $_GET["start"] = 1;
          $show = 10;

          $dir = ".";
          $thedir = opendir($dir);
          while (false !== ($file = readdir($thedir ))){
          if (in_array($file , array(".", ".."))) continue;
          $files[] = $file;
          }
          $pages = ceil(count($fil es)/$show);

          foreach ($files as $file){
          $nr++;
          if ($nr >= $_GET["start"] && $nr < $_GET["start"]+$show){
          print "<li$nr. $file\n";
          }
          }

          ?>
          --
          Sandman[.net]

          Comment

          Working...