I am new to PHP. I would like to read files from a specific folder / directory. I do not want to add subfolders or files to them. I just want to specify direct files inside the directory. I ended up with 3 solutions, glob() , readdir() and scandir() . I can make a list of files, for example:
foreach (glob("*.*") as $filename) { echo $filename."<br />"; }
and
if (is_dir($dir)) { if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { echo "filename: .".$file."<br />"; } closedir($dh); } }
and
$files = scandir($dir); foreach($files as $val){ echo $val; }
Which one can be faster and more efficient?
Thanks in advance ... :)
source share