1. <i id='gB3KB'><tr id='gB3KB'><dt id='gB3KB'><q id='gB3KB'><span id='gB3KB'><b id='gB3KB'><form id='gB3KB'><ins id='gB3KB'></ins><ul id='gB3KB'></ul><sub id='gB3KB'></sub></form><legend id='gB3KB'></legend><bdo id='gB3KB'><pre id='gB3KB'><center id='gB3KB'></center></pre></bdo></b><th id='gB3KB'></th></span></q></dt></tr></i><div id='gB3KB'><tfoot id='gB3KB'></tfoot><dl id='gB3KB'><fieldset id='gB3KB'></fieldset></dl></div>
  2. <legend id='gB3KB'><style id='gB3KB'><dir id='gB3KB'><q id='gB3KB'></q></dir></style></legend>
    • <bdo id='gB3KB'></bdo><ul id='gB3KB'></ul>

    1. <small id='gB3KB'></small><noframes id='gB3KB'>

      <tfoot id='gB3KB'></tfoot>

      使用 PHP 返回文件夹内的文件总数

      Return total number of files within a folder using PHP(使用 PHP 返回文件夹内的文件总数)
        <tbody id='vVzW9'></tbody>

          <bdo id='vVzW9'></bdo><ul id='vVzW9'></ul>

          <small id='vVzW9'></small><noframes id='vVzW9'>

          • <tfoot id='vVzW9'></tfoot>

              <legend id='vVzW9'><style id='vVzW9'><dir id='vVzW9'><q id='vVzW9'></q></dir></style></legend>

              1. <i id='vVzW9'><tr id='vVzW9'><dt id='vVzW9'><q id='vVzW9'><span id='vVzW9'><b id='vVzW9'><form id='vVzW9'><ins id='vVzW9'></ins><ul id='vVzW9'></ul><sub id='vVzW9'></sub></form><legend id='vVzW9'></legend><bdo id='vVzW9'><pre id='vVzW9'><center id='vVzW9'></center></pre></bdo></b><th id='vVzW9'></th></span></q></dt></tr></i><div id='vVzW9'><tfoot id='vVzW9'></tfoot><dl id='vVzW9'><fieldset id='vVzW9'></fieldset></dl></div>
              2. 本文介绍了使用 PHP 返回文件夹内的文件总数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                是否有更好/更简单的方法来查找目录中的图像数量并将它们输出到变量?

                Is there a better/simpler way to find the number of images in a directory and output them to a variable?

                function dirCount($dir) {
                  $x = 0;
                  while (($file = readdir($dir)) !== false) {
                    if (isImage($file)) {$x = $x + 1}
                  }
                  return $x;
                }
                

                这样的方法好像很长,有没有更简单的方法?

                This seems like such a long way of doing this, is there no simpler way?

                注意:如果文件是图像,isImage() 函数返回 true.

                Note: The isImage() function returns true if the file is an image.

                推荐答案

                查看 DirectoryIterator 的标准 PHP 库(又名 SPL):

                Check out the Standard PHP Library (aka SPL) for DirectoryIterator:

                $dir = new DirectoryIterator('/path/to/dir');
                foreach($dir as $file ){
                  $x += (isImage($file)) ? 1 : 0;
                }
                

                (仅供参考,有一个名为 iterator_count() 的未记录函数,但我想现在最好不要依赖它.而且你需要过滤掉看不见的东西,比如 . 和 .. 无论如何.)

                (FYI there is an undocumented function called iterator_count() but probably best not to rely on it for now I would imagine. And you'd need to filter out unseen stuff like . and .. anyway.)

                这篇关于使用 PHP 返回文件夹内的文件总数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)
              3. <tfoot id='KxHVG'></tfoot>
                      <tbody id='KxHVG'></tbody>

                      <legend id='KxHVG'><style id='KxHVG'><dir id='KxHVG'><q id='KxHVG'></q></dir></style></legend>
                      • <bdo id='KxHVG'></bdo><ul id='KxHVG'></ul>
                        • <i id='KxHVG'><tr id='KxHVG'><dt id='KxHVG'><q id='KxHVG'><span id='KxHVG'><b id='KxHVG'><form id='KxHVG'><ins id='KxHVG'></ins><ul id='KxHVG'></ul><sub id='KxHVG'></sub></form><legend id='KxHVG'></legend><bdo id='KxHVG'><pre id='KxHVG'><center id='KxHVG'></center></pre></bdo></b><th id='KxHVG'></th></span></q></dt></tr></i><div id='KxHVG'><tfoot id='KxHVG'></tfoot><dl id='KxHVG'><fieldset id='KxHVG'></fieldset></dl></div>

                          <small id='KxHVG'></small><noframes id='KxHVG'>