> I wrote a script to display all file in a directory. Here is my script
(snip)
> This is working fine. But it displays all files in 1 single page. Here is
> what i wanna do, but i don't know how to do it.
> I wanna display 15 files names at once, and have prev. and next buttons
and
> the end, when i click on next, it will display the next 15 files.

If you have to do it all in PHP, I would pass a start-file index to the
page; something like this:

<?php
    $ind = ( isset($ind) ? $ind : 0 );

    $dir_name = "e:\celebs\christina_aguilera";
    $dir = opendir($dir_name);

    $prev = ( $ind > 0 );                    // should 'prev' be active?
    $next = false;                                // should 'next' be
active?
    $ignore = array(".", "..");            // files to skip
    $i = 0;
    while ($fname = readdir($dir)) {
        if (in_array($fname, $ignore))
            continue;

        if ($i >= $ind) {
            if ($i < $ind + 15) {
                echo "\n<br>&nbsp;&nbsp;$fname";
            }
            else {
                $next = true;                    // more files; make 'next'
active
                break;
            }
        }
        $i++;
    }
    closedir($dir);

    $prev_pre = ( $prev ? '<a href="#?ind='.max($ind-15,0).'">' : '' );
    $prev_post = ( $prev ? '</a>' : '' );
    $next_pre = ( $next ? '<a href="#?ind='.$ind+15.'">' : '' );
    $next_post = ( $next ? '</a>' : '' );
    echo "\n<br>$prev_pre &lt;&lt;prev $prev_post | $next_pre next&gt;&gt;
$next_post";
?>

This will skip '.' and '..' without counting them, will enable/disable the
'prev' and 'next' links as needed, will ignore all files past $ind+16 (it
has to read one past the end to know if 'next' should be enabled), and will
automatically stop when it runs out of files.  It will work for all
browsers, at a cost of increased server load.

Personally, I would consider writing all the filenames into a JavaScript
array, and do the paging on the client.



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to