aleX_hill Posted March 21, 2008 Share Posted March 21, 2008 Can someone point me in the direction of a script that will read the contents of a folder (they are all images) and then put them in a table, with pagination? I have a script that will read the files and put them in a table, but dont know how to start from half way through the folder on page 2 etc (without first making x readdir requests). <?php // Type in the full / absolute path to the folder... $path = $_SERVER[ 'DOCUMENT_ROOT' ] . "/clients/client1/"; // This opens the folder... $dir_handle = @opendir($path) or die("Unable to open $path"); ?> <table><tr> <?php $i = 0; // This loops through the files... while ($file = readdir($dir_handle)) { if($i == 4) { $i = 0; echo "</tr><tr>"; } if($file == "." || $file == ".." || $file == "index.php" ) continue; echo "<td><img src='client1/$file' height='400'></td>"; $i++; } ?> </tr></table> <?php // Close it... closedir($dir_handle); ?> Any help is greatly appreciated. Alex Quote Link to comment Share on other sites More sharing options...
Jeremysr Posted March 21, 2008 Share Posted March 21, 2008 You'll want to read all the filenames into an array. Then have a variable in the URL, like $_GET['start']. That will be index of the filename array that you'll start on. Then print the next ten after that (or however many you want per page). $files_per_page = 10; $files = scandir($path); for ($file_count = 0; $file_count < count($files); $file_count++) { if ($file_count >= $_GET['start'] && $file_count <= $_GET['start']+$files_per_page) { // You'd print the file here } } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.