Like, we have folder /images/
, it has some files inside.
And the script /scripts/listing.php
How can we get names of the all files inside folder /images/
, in listing.php
?
Thanks.
<?php
if ($handle = opendir('/path/to/files')) {
echo "Directory handle: $handle\n";
echo "Files:\n";
/* This is the correct way to loop over the directory. */
while (false !== ($file = readdir($handle))) {
echo "$file\n";
}
/* This is the WRONG way to loop over the directory. */
while ($file = readdir($handle)) {
echo "$file\n";
}
closedir($handle);
}
?>
See: readdir()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With