title: Reading file directly from folder in php
body: <p>I want my code to read the file(image) from directly from the folder. But only one file(image) it read and still reading it again (infinity) it didn't stop display one same file(image). But not all the other five different files (image).</p>
  <pre><code>&lt;?php
  
      $dir_path = &quot;image/gundam/&quot;;
      $extensions_array = array('jpg','png','jpeg');
  
      if(is_dir($dir_path)){
           $files = scandir($dir_path);
  
           for($i = 0; $i &lt; count($files); $i++){
               while($files[$i] !='.' &amp;&amp; $files[$i] !='..'){
                    // get file name
                    echo &quot;File Name -&gt; $files[$i]&lt;br&gt;&quot;;
  
                    // get file extension
                    $file = pathinfo($files[$i]);
                    $extension = $file['extension'];
                    echo &quot;File Extension-&gt; $extension&lt;br&gt;&quot;;
  
                    // check file extension
                    if(in_array($extension, $extensions_array)){
                    // show image
                        echo &quot;&lt;img src='$dir_path$files[$i]' style='width:100px;height:100px;'&gt;&lt;br&gt;&quot;;
                    }
                }
            }
       }
   ?&gt;
  </code></pre>