draxu26480 2010-12-04 02:00
浏览 53
已采纳

列出目录/解压缩文件扩展名中的文件的问题

I'm attempting to list only jpg files in a directory. There's over 200, but using the code below, only about 100 get listed. I've tried different variations for extracting the file extension, but this has been the only one that's worked: $sub = substr($file, -3);

Can anyone tell me why all of the files are not showing up?

Complete source:

<?php
  require('index.inc');
  $page = new buildpage();
  $page->buildHeader();

   $currentdir = '/home/tim/Documents/Web/';
   $dir = opendir($currentdir);
   echo "<ol>";
   while ($file = readdir($dir)){
      $file = readdir($dir);
      $sub = substr($file, -3);
      $ext = "jpg";
      if (strcasecmp($sub, $ext) == 0) {   
           echo "<li>$file</li>";
      }
   }
   echo "</ol>";
?>
  • 写回答

2条回答 默认 最新

  • doulutian4843 2010-12-04 02:04
    关注

    You have

    $file = readdir($dir)

    twice in there. So its read twice everytime.Thus 200 becoming 100. Take out the second one and it should work.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作