【问题标题】:Why php sorting my Images different on different Platforms为什么 php 在不同平台上对我的图像进行不同的排序
【发布时间】:2016-02-17 02:24:06
【问题描述】:

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

我已经试过了 natsort();但也许我实施错了。 我试过 scandir 但我没有找到图像(试图将路径更改为 rootpath 也没有工作)

<?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);
?>

【问题讨论】:

    标签: php sorting directory


    【解决方案1】:

    这可以按我的预期工作并订购图像。示例(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++;
        }
       } 
    

    ?>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-17
      • 2018-06-22
      • 2020-09-19
      • 1970-01-01
      • 2015-07-18
      • 2016-05-21
      相关资源
      最近更新 更多