0

If I have a directory like such "/personal/private/perfection" Can I get it's files using foreach and be able to output their contents using file_get_contents? If not, please say a better way. My current code is:

foreach("/personal/private/perfection" as $file) {
    echo file_get_contents($file . "\n");
}
Hydra
  • 1
  • 1
  • You could reuse this script. See : https://stackoverflow.com/questions/46118493/create-show-menu-in-powershell-depending-on-variables/46118757?noredirect=1#comment79201244_46118757 Axel – xsouxsou Sep 18 '17 at 15:38
  • Before posting a question, you should have done some research. Please read [How much research effort is expected of Stack Overflow users?](https://meta.stackoverflow.com/questions/261592/how-much-research-effort-is-expected-of-stack-overflow-users). There are _plenty_ of guides about listing files in folders with PHP. – M. Eriksson Sep 18 '17 at 15:39

1 Answers1

0

You just need the glob() function :

foreach(glob("/personal/private/perfection/../*") as $file) {
    echo file_get_contents($file);
}

http://php.net/glob

Calimero
  • 4,238
  • 1
  • 23
  • 34