this code:
$dir = "img/"; $files = scandir($dir); ($i=0; $i <= count($files); $i++) { echo $files[$i]."<br/>"; } echo count($files); count of array returns value of 2 on empty array, cheched hidden files, 0 resault. can cause this? var_dump resault
array(7) { [0]=> string(1) "." [1]=> string(2) ".." [2]=> string(8) "img1.gif" [3]=> string(8) "img2.gif" [4]=> string(8) "img3.jpg" [5]=> string(8) "img4.png" [6]=> string(8) "img5.png" }
its because array contain '.' & '..' 2 file names.
you can rid of using below code
$files = array_diff(scandir($dir), array('..', '.'));
Comments
Post a Comment