Folder list with Pagination

This is a discussion on Folder list with Pagination within the PHP Language forums, part of the PHP Programming Forums category; I'm looing for a simple PHP file list program, that will show all the files in a folder, but ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-11-2006
jerryyang_la1@yahoo.com
 
Posts: n/a
Default 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

Reply With Quote
  #2 (permalink)  
Old 09-11-2006
Noodle
 
Posts: n/a
Default Re: Folder list with Pagination


jerryyang_la1@yahoo.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($handle);
} ?>

Reply With Quote
  #3 (permalink)  
Old 09-11-2006
Noodle
 
Posts: n/a
Default Re: Folder list with Pagination


jerryyang_la1@yahoo.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.

Reply With Quote
  #4 (permalink)  
Old 09-13-2006
jerryyang_la1@yahoo.com
 
Posts: n/a
Default Re: Folder list with Pagination


Noodle wrote:
> jerryyang_la1@yahoo.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($handle);
> } ?>


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

Reply With Quote
  #5 (permalink)  
Old 09-13-2006
Sandman
 
Posts: n/a
Default Re: Folder list with Pagination

In article <1158137962.446398.40570@d34g2000cwd.googlegroups. com>,
jerryyang_la1@yahoo.com wrote:

> Noodle wrote:
> > jerryyang_la1@yahoo.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($handle);
> > } ?>

>
> 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($files)/$show);

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

?>
--
Sandman[.net]
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 02:20 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0