• <legend id='v8ewU'><style id='v8ewU'><dir id='v8ewU'><q id='v8ewU'></q></dir></style></legend>

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

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

        <i id='v8ewU'><tr id='v8ewU'><dt id='v8ewU'><q id='v8ewU'><span id='v8ewU'><b id='v8ewU'><form id='v8ewU'><ins id='v8ewU'></ins><ul id='v8ewU'></ul><sub id='v8ewU'></sub></form><legend id='v8ewU'></legend><bdo id='v8ewU'><pre id='v8ewU'><center id='v8ewU'></center></pre></bdo></b><th id='v8ewU'></th></span></q></dt></tr></i><div id='v8ewU'><tfoot id='v8ewU'></tfoot><dl id='v8ewU'><fieldset id='v8ewU'></fieldset></dl></div>
        <tfoot id='v8ewU'></tfoot>
      1. 如何使用 PHP 检查目录是否为空?

        How can I use PHP to check if a directory is empty?(如何使用 PHP 检查目录是否为空?)

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

              <small id='4s9E0'></small><noframes id='4s9E0'>

              • <bdo id='4s9E0'></bdo><ul id='4s9E0'></ul>

                • 本文介绍了如何使用 PHP 检查目录是否为空?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用以下脚本读取目录.如果目录中没有文件,它应该显示为空.问题是,即使里面有文件,它也一直说目录是空的,反之亦然.

                  I am using the following script to read a directory. If there is no file in the directory it should say empty. The problem is, it just keeps saying the directory is empty even though there ARE files inside and vice versa.

                  <?php
                  $pid = $_GET["prodref"];
                  $dir = '/assets/'.$pid.'/v';
                  $q   = (count(glob("$dir/*")) === 0) ? 'Empty' : 'Not empty';
                      
                  if ($q=="Empty") 
                      echo "the folder is empty"; 
                  else
                      echo "the folder is NOT empty";
                  ?>
                  

                  推荐答案

                  看来你需要 scandir 而不是 glob,因为 glob 看不到 unix 隐藏文件.

                  It seems that you need scandir instead of glob, as glob can't see unix hidden files.

                  <?php
                  $pid = basename($_GET["prodref"]); //let's sanitize it a bit
                  $dir = "/assets/$pid/v";
                  
                  if (is_dir_empty($dir)) {
                    echo "the folder is empty"; 
                  }else{
                    echo "the folder is NOT empty";
                  }
                  
                  function is_dir_empty($dir) {
                    if (!is_readable($dir)) return null; 
                    return (count(scandir($dir)) == 2);
                  }
                  ?>
                  

                  请注意,这段代码不是效率的顶峰,因为没有必要读取所有文件只是为了判断目录是否为空.所以,更好的版本是

                  Note that this code is not the summit of efficiency, as it's unnecessary to read all the files only to tell if directory is empty. So, the better version would be

                  function dir_is_empty($dir) {
                    $handle = opendir($dir);
                    while (false !== ($entry = readdir($handle))) {
                      if ($entry != "." && $entry != "..") {
                        closedir($handle);
                        return false;
                      }
                    }
                    closedir($handle);
                    return true;
                  }
                  

                  顺便说一句,不要使用来代替布尔值.后者的真正目的是告诉您某些东西是否为空.一个

                  By the way, do not use words to substitute boolean values. The very purpose of the latter is to tell you if something empty or not. An

                  a === b
                  

                  表达式在编程语言方面已经返回EmptyNon Empty,分别是falsetrue - 所以,您可以在没有任何中间值的情况下在 IF() 等控制结构中使用结果

                  expression already returns Empty or Non Empty in terms of programming language, false or true respectively - so, you can use the very result in control structures like IF() without any intermediate values

                  这篇关于如何使用 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 的问题)

                  <tfoot id='rwrWx'></tfoot>

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

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

                        • <bdo id='rwrWx'></bdo><ul id='rwrWx'></ul>

                              <tbody id='rwrWx'></tbody>