简体   繁体   English

使用PHP5在Web树外部的scandir

[英]scandir outside web tree using PHP5

I'm looking for a way to get directory listing for files that are outside the webserver's tree, for example i want to list all files and folders under '/home' directory and put them in an array (just as scandir does). 我正在寻找一种获取网络服务器树外文件目录列表的方法,例如,我想列出“ / home”目录下的所有文件和文件夹,并将它们放入数组中(就像scandir一样)。

I can 'sudo su' to a user that has rights to check the directory content but i don't know how to convert a directory listing that i could get from a 我可以对拥有权限检查目​​录内容的用户进行“ sudo su”操作,但是我不知道如何转换我可以从

exec ('ls -la /home');

Or maybe with a bash script ? 还是使用bash脚本?

Difficult. 难。 The 'su' command does not take the password from stdin for security reasons, and that makes it pretty much impossible to use it from PHP. 出于安全原因,'su'命令不会从stdin获取密码,因此几乎不可能从PHP使用它。

You need to find an alternative. 您需要找到替代方法。

Will the list be huge? 列表会很大吗? Does it have to be real time? 它必须是实时的吗?

Can you perhaps edit the crontab of that other user who has permissions to list files? 您是否可以编辑其他有权列出文件的用户的crontab? If yes, then you could execute a command that outputs the list of files to some text file, which you then would be able to read from PHP. 如果是,则可以执行将文件列表输出到某些文本文件的命令,然后可以从PHP读取该文本文件。 Cron can run once every minute, but if your directory does not change very often, then that would work. Cron可以每分钟运行一次,但是如果您的目录不经常更改,那么它将起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM