rgb192
asked on
all the files in a directory php for windows
php for windows
want to iterate through all the files in a directory
save into an array
foreach file, do something
I want to echo the contents of each file (but not with this question)
want to iterate through all the files in a directory
save into an array
foreach file, do something
I want to echo the contents of each file (but not with this question)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
<?php
$filesarray = array();
if ($handle = opendir('C:/gyb/')) {
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != ".." && is_file($entry)) {
echo "$entry<br />";
$filesarray[] = $entry;
}
}
closedir($handle);
}
print_r($filesarray);
?>
no output
I think because it says if
or
becuase I changed line 5 to add my windows directory in error
ASKER
this answer works in the same directory
thanks
thanks
Another useful function: http://php.net/manual/en/function.getcwd.php
use readdir() to read the list of files and within while loop do the reading of each file and do whatever your scenario requires
http://php.net/manual/en/function.readdir.php