loop through files php

Solutions on MaxInterview for loop through files php by the best coders in the world

showing results for - "loop through files php"
Stefania
21 Sep 2017
1<?php 
2	$folder = '/path/'; //directory or folder to loop through
3	$checkFiles = scandir($folder); //scan folder content
4	$fileCount = count($checkFiles); //count number of files in the directory
5	$i = 0; //set for iteration;
6	while($i < $fileCount){
7    	$file = $checkFiles[$i]; //each file is stored in an array ... 
8      	if($file = '.' || $file = '..'){
9        	//echo nothing
10        }else{
11          echo $file; // file names are printed out
12        }
13    }
14?>