roflwaffle
roflwaffle

Reputation: 30646

PHP list directories and files

What would be the easiest way to have a page where it will display a list of directories that the user can click on to open, where there will be more directories or eventually files to download and have it all happen on the same page?

Upvotes: 1

Views: 5760

Answers (3)

Steven Surowiec
Steven Surowiec

Reputation: 10220

For something basic you are probably better off just adding 'Options +Indexes' to an .htaccess for that folder. However if you want something more complicated and are running on PHP5 you can use the Directory Iterator to accomplish this. The most important thing to consider is security.

You do not want to just dump the directory path into $_REQUEST and then blindly let the user load that directory. You need to ensure you have some security in place to prevent, for example, some one from just changing the request and asking to see the entire /var directory. The best way to do this is to only pass the current file/folder relative to the docroot and make sure to strip out any .. so some one can't just say ../../var or something similar.

Upvotes: 5

Frans
Frans

Reputation:

Put this in the .htaccess file:

Options +Indexes

Upvotes: 1

Marko
Marko

Reputation: 31375

To remove index.php from the folder and allow directory browsing for that folder and subfolders in htacceess.

Upvotes: 6

Related Questions