[Solved]PHP directory listing |
Author: |
Message: |
Mike
Elite Member
Meet the Spam Family!
Posts: 2795 Reputation: 48
32 / /
Joined: Mar 2003
|
O.P. [Solved]PHP directory listing
Hello.
How can I list the contents of a directory using PHP?
I would like the newer files to be shown first.
I have searched google and found this: http://webxadmin.free.fr/article/php-dir-list-and-sort-by-date-209.php
However, I cant get it working...
I set it to list the root ( / ) however, all I get is an empty page.
Thanks!
Edit: I forgot to say, that I'm using PHP 5.0.4
This post was edited on 02-13-2006 at 05:48 AM by Mike.
|
|
02-11-2006 08:15 AM |
|
|
Dempsey
Scripting Contest Winner
http://AdamDempsey.net
Posts: 2395 Reputation: 53
38 / /
Joined: Jul 2003
|
RE: PHP directory listing
Well if its not your server, you probably don't have root access, thats why it doesn't work. Try listing a folder you have access to and see if that works.
|
|
02-11-2006 08:23 AM |
|
|
Mike
Elite Member
Meet the Spam Family!
Posts: 2795 Reputation: 48
32 / /
Joined: Mar 2003
|
O.P. RE: PHP directory listing
Well, I'm hosted by dt...
However, Im not really sure what directory I should pass to list....
|
|
02-11-2006 08:32 AM |
|
|
Eljay
Elite Member
:O
Posts: 2949 Reputation: 77
– / / –
Joined: May 2004
|
RE: PHP directory listing
quote: Originally posted by Mike
Well, I'm hosted by dt...
However, Im not really sure what directory I should pass to list....
if its current directory you want to list its ./ not /
|
|
02-11-2006 08:34 AM |
|
|
Mike
Elite Member
Meet the Spam Family!
Posts: 2795 Reputation: 48
32 / /
Joined: Mar 2003
|
O.P. RE: PHP directory listing
quote: Originally posted by Eljay
quote: Originally posted by Mike
Well, I'm hosted by dt...
However, Im not really sure what directory I should pass to list....
if its current directory you want to list its ./ not /
Just tried, still empty page
|
|
02-11-2006 08:35 AM |
|
|
WDZ
Former Admin
Posts: 7106 Reputation: 107
– / /
Joined: Mar 2002
|
RE: PHP directory listing
Well, that code alone doesn't output anything... you need to handle that yourself...
|
|
02-11-2006 08:38 AM |
|
|
Eljay
Elite Member
:O
Posts: 2949 Reputation: 77
– / / –
Joined: May 2004
|
RE: PHP directory listing
quote: Originally posted by Mike
quote: Originally posted by Eljay
quote: Originally posted by Mike
Well, I'm hosted by dt...
However, Im not really sure what directory I should pass to list....
if its current directory you want to list its ./ not /
Just tried, still empty page
tried print_r($Files); ¬¬
that code is just to get the array
edit: WDZ
This post was edited on 02-11-2006 at 08:38 AM by Eljay.
|
|
02-11-2006 08:38 AM |
|
|
Mike
Elite Member
Meet the Spam Family!
Posts: 2795 Reputation: 48
32 / /
Joined: Mar 2003
|
O.P. RE: PHP directory listing
Now i get an output, but it looks weird
Something like this:
quote: Array ( [0] => Array ( [0] => ./mediaplayer.php [1] => 1137315439 )
I guess I will have to loop through the arrays and echo(); them?
This post was edited on 02-11-2006 at 08:42 AM by Mike.
|
|
02-11-2006 08:40 AM |
|
|
Eljay
Elite Member
:O
Posts: 2949 Reputation: 77
– / / –
Joined: May 2004
|
RE: PHP directory listing
quote: Originally posted by Mike
Now i get an output, but it looks weird
Something like this:
I guess I will have to loop through the arrays and echo(); them?
yes
|
|
02-11-2006 08:43 AM |
|
|
WDZ
Former Admin
Posts: 7106 Reputation: 107
– / /
Joined: Mar 2002
|
RE: PHP directory listing
Some example code...
code: echo "<ul>\r\n";
foreach($Files as $file) {
$file_path = $file[0];
$file_name = basename($file_path);
$last_modified = $file[1];
$last_modified_str = date('Y-m-d H:i:s', $last_modified);
echo "<li>$last_modified_str $file_name</li>\r\n";
}
echo "</ul>";
|
|
02-11-2006 08:49 AM |
|
|
Pages: (2):
« First
[ 1 ]
2
»
Last »
|
|