2017-09-18 32 views
0

如果我有一个像“/ personal/private/perfection”这样的目录 我可以使用foreach获取它的文件,并且能够使用file_get_contents输出它们的内容吗?如果没有,请说一个更好的方法。 我当前的代码是:使用foreach获取父目录的文件

foreach("/personal/private/perfection" as $file) { 
    echo file_get_contents($file . "\n"); 
} 
+0

你可以重复使用该脚本。见:https://stackoverflow.com/questions/46118493/create-show-menu-in-powershell-depending-on-variables/46118757?noredirect=1#comment79201244_46118757 Axel – xsouxsou

+0

在发布问题之前,你应该做一些研究。请阅读[Stack Overflow用户需要多少研究工作?](https://meta.stackoverflow.com/questions/261592/how-much-research-effort-is-expected-of-stack-overflow-users) 。有关于使用PHP在文件夹中列出文件的指南_plenty_。 –

回答

0

你只需要​​3210功能:

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

http://php.net/glob