2017-09-18 30 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