Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 8th, 2012  |  syntax: None  |  size: 0.93 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Display contents of static files across multiple pages in PHP
  2. function printFile($file) {
  3.   $handle = fopen("$file", "r");
  4.   while (!feof($handle)) {
  5.     echo fgets($handle) . "<br>";
  6.   }
  7.   echo "<hr>";
  8.   fclose($handle);
  9. }
  10.  
  11.  
  12.  
  13. $files = scandir($directory);
  14. $number = count($files, 0);
  15. while ($number > 2) {
  16.   $number--;
  17.   $FileToPrint = $directory . $files["$number"];
  18.   echo $FileToPrint . "<br>";
  19.   printFile("$FileToPrint");
  20. }
  21.        
  22. // initialize some settings
  23. $perPage = 20;
  24. $page = intval($_GET['page']);
  25.  
  26. // getting the files (just *.txt)
  27. $files = glob('directory/*.txt');
  28. $numFiles = count($files);
  29.  
  30. // displaying the files for this page
  31. $offset = $page * $perPage;
  32. for($i = $offset; $i < ($offset + $perPage); $i++){
  33.     // just print the filename for now
  34.      echo $files[$i]. "<br>";
  35. }
  36.  
  37.  
  38. // page browser
  39. $numPages = ceil($numFiles / $perPage);
  40. for($i = 0; $i < $numPages; $i++){
  41.     echo '<a href="yourpage.php?page='.$i.'">'.$i.'</a>';
  42. }