Forum Moderators: coopster

Message Too Old, No Replies

directory contents display script

allowing users to see the contents of a given directory

         

ben_j

10:09 am on Apr 20, 2003 (gmt 0)

10+ Year Member



I have a page on my site that allows users to upload content to a pre-determined folder on my server. I would like to be able to show these users a list of the contents in that folder so that they can then use these filenames to complete url strings enabling them to look at each others uploaded work. I know I can do this by simpley linking to that folder (so long as no-one uploads a file called index.htm), but I would like to be able to dress that page up in keeping with the rest of the site design as well as including extra information (such as the rest of the url string) at the top of this page.

I've tried searching for pre-written php scripts that would do this, but as I don't know what to call a script like this (a 'directory contents display' script?) I have had little luck.

Does anyone know of a script out there that would do this or could some one maybe point me in the right direction to keep looking please?

Many thanks.

dmorison

10:30 am on Apr 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Ben,

The directory object, created using opendir() should give you everything you need to generate a fancy page from a list of files in a particular directory...

[php.net...]

ShawnR

10:32 am on Apr 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You could use an exec() function. For example

<?php
exec("ls -al .", $output, $return);
foreach ($output as $file )
print $file <br>;
?>

You should also check the $return code to make sure the ls was successful, but you get the idea. Of course, instead of just printing the file names, you could parse them and put the filename part in <a> tags so that your users could navigate to them, etc.

Shawn

wruk999

10:39 am on Apr 20, 2003 (gmt 0)

10+ Year Member



Hi ben_j,

There is a script called WebExplorer, which has allows users to display files in a directory, view them, chmod them etc etc. You could take this script, and just use the list file section.

Script at: suneworld.com/programs/

Regards,
wruk999

ben_j

10:43 am on Apr 20, 2003 (gmt 0)

10+ Year Member



fantatstic, I'll get back to you all once I'm further down the line.

Many thanks.

ShawnR

11:29 am on Apr 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



retraction...

Its always better to use a function native to the language rather than an external system call. It makes for more portable code. So pls ignore my suggestion, as dmorison's suggestion is a better way to go. When I sent my previous post, I hadn't seen his.

Shawn