Click to See Complete Forum and Search --> : listing files


winterflood_j
07-02-2003, 07:56 AM
is there any way to get a list of files and folders contained in a location?
say we have location www.blah.com:

www.blah.com
!
+one(folder)
!
+two(folder)
!
+index.html

and I want a way of diplaying that one, two and index.html are there ,starting from the location...

thanx

pyro
07-02-2003, 08:09 AM
This will do it in PHP:

<?PHP
$root = $_SERVER["DOCUMENT_ROOT"]; #set the root directory
$directory = ""; #leave blank to display the root directory
$path = $root.$directory; #concatenat the root and the desired directory
$handle = opendir($path); #open the directory
while ($item = readdir($handle)) { #loop through the directory
echo $item."<br>"; #echo the files/directories
}
closedir($handle); #close the directory
?>

winterflood_j
07-02-2003, 08:28 AM
ok if I get it (I dont know php)
this will list all files sitting next to itself

but,(sorry i should have said) i want the files in a particular location, not that of this file..
I dont need a prompt or anything, i can hard code the adress but is it possible?

will this recurse subdirectories btw? (just in case, not important)

thx
Jo

pyro
07-02-2003, 08:41 AM
To answer questions 1 and 2:

It will list all the files in the directory you specify here:

$root = $_SERVER["DOCUMENT_ROOT"]; #set the root directory
$directory = ""; #leave blank to display the root directory

The above will display your root directory, if you want it to display your www.yourdomain.com/images folder, you would do this:

$root = $_SERVER["DOCUMENT_ROOT"]; #set the root directory
$directory = "/images"; #leave blank to display the root directory

And, for you third question, no, it will not recurse subdirectories, though it could be made to, with a bit more work.

winterflood_j
07-02-2003, 08:51 AM
well
what would i have to do to display www.someoneshome.com then?

replace "DOCUMENT_ROOT" by the adress?
jo

pyro
07-02-2003, 08:54 AM
The original code should work fine. Make sure you saved the file with a .php extention.

winterflood_j
07-02-2003, 09:17 AM
i mean showing www.someoneelsesdomain.com
and the file is, say perso.lycos.fr/jo/blah.php

jo

pyro
07-02-2003, 09:18 AM
No, you can't display the file listing of someone else domain. (Thank God)...

winterflood_j
07-02-2003, 09:22 AM
ok I see