为什么php在不同的平台上对我的图像进行不同的排序


Why php sorting my Images different on different Platforms

这段代码在Xampp上做了它应该做的事情(按字母顺序存储图像),但如果我在托管服务上上传它,它会随机订购。

我已经试过natsort();但也许我实施错了。我尝试了scandir,但我没有找到图像(试图将路径更改为根路径也不起作用)

<?php 
$path = "./upload/outdoor/server/php/files/";
$dh = opendir($path);
$i=1;
while (($file = readdir($dh)) !== false) {
  if($file != "." && $file != ".gitignore" && $file != "thumbnail" && $file != ".." && $file != "index.php" && $file != ".htaccess" && $file != "error_log" && $file != "cgi-bin") {
    //Image Output
    echo "<div>
    <div href='$path/$file'>
    <img src='$path/$file' />
    </div>
    </div>";
    $i++;}
  } 
closedir($dh);
?>

这样可以按照我的预期工作并对图像进行排序。示例(01_Image、02_Image和03_Image现在分别位于图库的第一、第二和第三位)

  <?php 
  $path = "./upload/art/server/php/files/";
  $ignore = array('.', '..', '.gitignore', 'thumbnail', 'index.php', '.htaccess');
  $i=1;
  $files = scandir($path);
  foreach($files as $file){
  if(!in_array($file, $ignore)) {
    //Image Output
    echo "<div>
     <img src='$path/$file' />
     </div>
     </div>";
     $i++;
    }
   } 

>