php sorted array and readfile not reading in order
<p>I am trying to write a php function to save and then display comments on an article.</p>

<p>In my save.php, I am formulating the file with:
<code>$file = "article1/comments/file".time().".txt";</code></p>

<p>Then using fwrite() to write to a directory.  </p>

<p>In my index I have:</p>

<pre>
if ($handle = opendir('article1/comments')) {
  while (false !== ($file = readdir($handle))) {
    if ($file != "." && $file != "..") {
      $files = array($file);
      sort($files);
      foreach($files as $comments){
        echo "&lt;div class='message'&gt;";
        readfile('article1/comments/'.$comments);
        echo "&lt/div&gt;";
      }
    }
  }
  closedir($handle);
}
</pre>

<p>For the most part this displays the comments in the correct order, but for some reason, some files are displaying out of order.  Furthermore, if I change sort() to rsort(), there is no change in how they are displayed.</p>

<p>I presume this is because readfile() is not following the sorted array's order.  So I am wondering for one, why readfile does not display the files in order from newest to oldest, and two, how can I make it display them correctly?</p>

<p>Thanks.</p>

<p>edit:  I copied the directory of comments from the live site to my local xampp installation, and the comments are displayed in order locally, but using the same code on my site results in comments not being in order.</p>
