tags:

views:

21

answers:

1

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).

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

exec ('ls -la /home');

Any ideas ? Or maybe with a bash script ?

A: 

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.

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? 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. Cron can run once every minute, but if your directory does not change very often, then that would work.

Anti Veeranna
found another way; php-cli returning base64. thanks
Disco