title: Paginate list of files in php
body: <p>I have php code for list all ".swf" files in a folder. (The name of the files is always: 
  "99-dd-mm-YY_HH-mm-ss.swf", example: "01-19-06-2011_18-40-00.swf".
  When I have more than 500 files in the folder is complicated to see and to refresh the page.</p>
  
  <p>I need paginate the list of files.</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;meta content="text/html; charset=UTF-8" http-equiv="content-type"&gt;
  &lt;title&gt;&lt;/title&gt;
  &lt;script type="text/javascript"&gt;
  function submitform()
  {    
    document.myform.submit();
  }
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;form name="myform" action="some.php" method="post"&gt;
  &lt;?php
     echo "\n&lt;br&gt;\n";
  
  
  echo "&lt;a href='javascript:this.location.reload();' style='color: #000000; font-weight: normal'&gt;Refresh&lt;/a&gt;&lt;/br&gt;";
     echo "&lt;tr&gt;\n&lt;td&gt;\n&lt;a href='javascript:javascript:history.go(-1)'&gt;\n";
     echo "&lt;img src='../../inc/img/back.png' alt='Back'";
     echo " border=0&gt;\n";
     echo "&lt;b&gt;&amp;nbsp;Back&lt;/b&gt;&lt;/a&gt;&lt;/td&gt;\n";
     echo "\n&lt;/tr&gt;\n";
     echo "\n&lt;br&gt;\n\n&lt;br&gt;\n";
  $folder='.';
  function order($a,$b){
  global $folder;
  $directory='.';
  return strcmp(strtolower($a), strtolower($b));
  }
  $folder=opendir($folder);
  while($files=readdir($folder)){
  
  $ext = pathinfo($files, PATHINFO_EXTENSION);
  if ($ext == 'swf')  {  //con esta línea saco el nombre index.php del listado
  $file[]=$files;
  usort($file, "order");
  }
  }
  $n = 0;
  foreach($file as $archiv){
     $n = $n + 1;
     $day = substr($archiv, 3,10);
     $day = str_replace("-","/", $day);
     $hour = substr($archiv, 14,8);
     $hour = str_replace("-",":", $hour);
     echo "&lt;img alt='Ver $archiv' src='../../inc/img/video.png'&gt; Video $n, Día: $day, hour: $hour\n ";
     echo "&lt;input type='submit' name='xxx' value='$archiv'&gt;&lt;/td&gt;\n";
     echo "\n&lt;/tr&gt;\n";
     echo "&lt;br&gt;";
  }
  closedir($folder);
     echo "\n&lt;br&gt;\n";
     echo "&lt;tr&gt;\n&lt;td&gt;\n&lt;a href='javascript:javascript:history.go(-1)'&gt;\n";
     echo "&lt;img src='../../inc/img/back.png' alt='Back'";
     echo " border=0&gt;\n";
     echo "&lt;b&gt;&amp;nbsp;Back&lt;/b&gt;&lt;/a&gt;&lt;/td&gt;\n";
     echo "\n&lt;/tr&gt;\n";
  ?&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>