title: Is there a way to loop over folder with scandir? I'm facing a problem when looping
body: <p>First I declared the variables to get the folders, and get the files into an array. See below</p>
  
  <pre><code>  $DOCROOT = $_SERVER['DOCUMENT_ROOT'];
    $dir    = $DOCROOT . '/php/pagamentos/resources/pagamentos';
    echo ($dir);
    $folder = array_diff(scandir($dir), array('.', '..'));
  </code></pre>
  
  <p>And I have the following array to loop:</p>
  
  <pre><code>array(4) {
    [2]=&gt;
    string(33) "BMEPS_out22002508200201095005.txt"
    [3]=&gt;
    string(33) "BMEPS_out22002508200204112009.txt"
    [4]=&gt;
    string(33) "BMEPS_out22002508200204125012.txt"
    [5]=&gt;
    string(33) "BMEPS_out22002508200205063000.txt"
  }
  </code></pre>
  
  <p>Then I start looping the array with the following code</p>
  
  <pre><code>foreach ($folder as $file) {
  
      $fp = fopen($file, "r") or die("Unable to open file!");
  
      echo $file;
  
  
      fclose($fp);
  }
  </code></pre>
  
  <p>But After all that I get the following error:</p>
  
  <pre><code>Warning: fopen(BMEPS_out22002508200204112009.txt): failed to open stream: No such file or directory in /var/www/html/php/pagamentos/index.php on line 40
  Unable to open file!
  </code></pre>