title: Failed to open dir : Bad file descriptor
body: <p>I face this problem. When i try to open the file list in other server which is 10.200.4.202. The error below appears.</p>
  
  <p>When I try using a local host, the file list can be viewed normally. I think the code is not the error but the server setting is not right.</p>
  
  <p>I used IIS 10.0, PHP 7.3.15</p>
  
  <p><strong>This is what appears on web</strong></p>
  
  <pre><code>status[parsererror] content[SyntaxError: Unexpected token &lt; in JSON at position 0]
  </code></pre>
  
  <p><strong>and this is the error in f12</strong></p>
  
  <pre><code>Warning:  
  opendir(\\10.200.4.202\y\1.InspCheckSheet_PDF\log,\\10.200.4.202\y\1.InspCheckSheet_PDF\log): Access is denied. (code: 5) in C:\PGMPIS_Web\public_html\ics_filing\loglist_sub.php on line 68
  
  
  Warning:  
  opendir(\\10.200.4.202\y\1.InspCheckSheet_PDF\log): failed to open dir: Bad file descriptor in C:\PGMPIS_Web\public_html\ics_filing\loglist_sub.php 
      on line 68
  
      {"querytime":"2020-05-14  09:58:50","other_status":"ERR","errmsg":""}
  </code></pre>
  
  <p><strong>Here's the code</strong></p>
  
  <pre><code>&lt;?php
  
      $dir_log = '\\\\10.200.4.202\\y\\1.InspCheckSheet_PDF\\log';
  
      require_once 'Log.php';
      $log    = Log::factory('file', 'log/okaspe.log',    'loglist_sub');     //$log-&gt;log('teeeeest!');
  
      //$type = $_REQUEST['type'];                    
  
  
  try{
      // Set query_time
      $emsg = "";
      $now = new DateTime();
      $res['querytime'] = $now-&gt;format('Y-m-d  H:i:s');
      //$res['querytime'] = $now-&gt;format('Y-m-d  g:i:s A');
  
  
  
      // Obtain log file name list → $fn[]
      $cnt = $pos = 0;
      unset($fn);         // clear $fn for safety
  
      if( $dir = opendir($dir_log) ) {                            // add @ infront of opendir by asyraf
          while (($file = readdir($dir)) !== false ) {
              $pos = strpos ($file, 'main_');                     // faster than preg_match() for simple search
  
              if( $pos !== false  &amp;&amp;  $pos == 0) {
                  $cnt++;
                  $fn[] = $file;
              }
          } 
  
          closedir($dir);
      } else {
          throw new Exception("Obtain Log File List failed......"); 
      }
  
  
      // sort in descending order
      rsort($fn);             //$log-&gt;log( print_r($fn, true) );
  
  
      //set response
      $res['list'] = $fn;
      $res['cnt']  = $cnt;
  
  
  
  
  } catch( Exception $e ) {
      // Functional Err exception
      $res["other_status"] = "ERR";
      $res["errmsg"      ] = $emsg;
  
      $log-&gt;log($e-&gt;getMessage(), PEAR_LOG_ERR);                  // logging
  
  
  } finally {
      //DB disconnect  (absolutely and always)
      $pdo = null;
  
  
      // Response in Json
      header('Content-Type: application/json; charset=utf-8');
      $json = json_encode( $res );            //$log-&gt;log($json, PEAR_LOG_ERR);
      echo $json;
  
  
  }
  exit;
  ?&gt;
  </code></pre>