|
-
Nov 1st, 2001, 08:40 PM
#1
Thread Starter
Fanatic Member
PHP Dir list
PHP Code:
<?
$dir_name = "C:\site";
$dir = opendir($dir_name);
$file_list = "<ul>";
while ($file_name = readdir($dir))
{
if (($file_name != ".") && ($file_name != ".."))
{
$file_list .= "<li>$file_name</li>";
}
}
$file_list .= "</ul>";
closedir($dir);
?>
<html>
<head>
<title>Files in <? echo "$dir_name"; ?></title>
Files in: <? echo "$dir_name"; ?>
<? echo "$file_list"; ?>
</body>
</html>
Is there a way I can just put this in a directory and have it list the files for that dir, and not have to manually specify the dir to list the files of?
-
Nov 1st, 2001, 09:59 PM
#2
try this:
$dir_name="./";
-
Nov 2nd, 2001, 02:03 AM
#3
Conquistador
I don't think you would get the wanted effect for the $dir_name printout then....
But other than that, it works
-
Nov 2nd, 2001, 09:03 PM
#4
Thread Starter
Fanatic Member
Yeah, well, the bad comes with the good but oh well. Thanks
-
Nov 2nd, 2001, 09:48 PM
#5
Conquistador
What about having good with good:
This should be what you are looking for:
Did you want the absolute path or just directory name?
Absolute Path:
PHP Code:
<?
$dir_name = "./";
$dir = opendir($dir_name);
$file_list = "<ul>";
while ($file_name = readdir($dir))
{
if (($file_name != ".") && ($file_name != ".."))
{
$file_list .= "<li>$file_name</li>";
}
}
$file_list .= "</ul>";
closedir($dir);
?>
<html>
<head>
<title>Files in <? echo getcwd(); ?></title>
Files in: <? echo getcwd(); ?>
<? echo "$file_list"; ?>
</body>
</html>
-
Nov 2nd, 2001, 09:53 PM
#6
Conquistador
Just the directory's name:
PHP Code:
<?
$dir_name = "./";
$dir = opendir($dir_name);
$file_list = "<ul>";
while ($file_name = readdir($dir))
{
if (($file_name != ".") && ($file_name != ".."))
{
$file_list .= "<li>$file_name</li>";
}
}
$file_list .= "</ul>";
closedir($dir);
$dir = substr(strrchr(getcwd(), "\\"), 1);
?>
<html>
<head>
<title>Files in <? echo $dir; ?></title>
Files in: <? echo $dir; ?>
<? echo "$file_list";?>
</body>
</html>
-
Nov 4th, 2001, 10:28 AM
#7
PowerPoster
how would you get the full path of the files?
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
-
Nov 4th, 2001, 06:43 PM
#8
Conquistador
I think you mean showing
Bullet: c:\apache\htdocs\index.php?
Here you go:
PHP Code:
<?
$dir_name = "./";
$dir = opendir($dir_name);
$file_list = "<ul>";
while ($file_name = readdir($dir))
{
if (($file_name != ".") && ($file_name != ".."))
{
$filename = getcwd()."\". $file_name;
$file_list .= "<li>getcwd()\$file_name</li>";
}
}
$file_list .= "</ul>";
closedir($dir);
?>
<html>
<head>
<title>Files in <? echo getcwd(); ?></title>
Files in: <? echo getcwd(); ?>
<? echo "$file_list"; ?>
</body>
</html>
-
Nov 4th, 2001, 07:08 PM
#9
PowerPoster
thanks, but, i get an error with it.
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
-
Nov 4th, 2001, 08:16 PM
#10
Thread Starter
Fanatic Member
No, what I meant was the relative path i guess. Like if I put the file in C:\site\folder\dir\images\ it should say "Files in images/", if I put it in C:\site\db\ it should say "Files in db/", etc.
Alcohol & calculus don't mix.
Never drink & derive.
-
Nov 4th, 2001, 08:26 PM
#11
Conquistador
Originally posted by Wynd
No, what I meant was the relative path i guess. Like if I put the file in C:\site\folder\dir\images\ it should say "Files in images/", if I put it in C:\site\db\ it should say "Files in db/", etc.
Have a look at my second post with code in it.
That does what you want ^^^^ here. 
Sail, what does the error say?
-
Nov 4th, 2001, 08:31 PM
#12
Conquistador
Yeah, sorry sail, I didn't test the code that i posted before, try this:
PHP Code:
<?
$dir_name = "./";
$dir = opendir($dir_name);
$file_list = "<ul>";
while ($file_name = readdir($dir))
{
if (($file_name != ".") && ($file_name != ".."))
{
$cwd = getcwd();
$file_list .= "<li>$cwd\\$file_name</li>";
}
}
$file_list .= "</ul>";
closedir($dir);
?>
<html>
<head>
<title>Files in <? echo getcwd(); ?></title>
Files in: <? echo getcwd(); ?>
<? echo "$file_list"; ?>
</body>
</html>
-
Nov 5th, 2001, 04:38 PM
#13
PowerPoster
cool, works now, thanks.
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
-
Nov 5th, 2001, 07:27 PM
#14
Thread Starter
Fanatic Member
Well that's partly what I want. I just want the script to output the directory name, not the whole path. (C:\path\dir\images produces "Files in images", C:\otherpath\scripts produces "Files in scripts", etc)
Alcohol & calculus don't mix.
Never drink & derive.
-
Nov 6th, 2001, 12:04 AM
#15
Conquistador
Have you tried this code yet:
I posted it before. 
PHP Code:
<?
$dir_name = "./";
$dir = opendir($dir_name);
$file_list = "<ul>";
while ($file_name = readdir($dir))
{
if (($file_name != ".") && ($file_name != ".."))
{
$file_list .= "<li>$file_name</li>";
}
}
$file_list .= "</ul>";
closedir($dir);
$dir = substr(strrchr(getcwd(), "\"), 1);
?>
<html>
<head>
<title>Files in <? echo $dir; ?></title>
Files in: <? echo $dir; ?>
<? echo "$file_list";?>
</body>
</html>
It does what you want...
-
Nov 6th, 2001, 06:59 PM
#16
Thread Starter
Fanatic Member
Thanks, it works. One thing though, you forgot to escape the backslash, that threw me for a loop till i figured it out
Alcohol & calculus don't mix.
Never drink & derive.
-
Nov 7th, 2001, 02:30 AM
#17
Conquistador
Woops, I didn't actually, but the php tags did that.
If you quote my message, you will see that i didn't forget to escape it
-
Nov 22nd, 2001, 01:28 AM
#18
PowerPoster
is there anyway to tell it how to sort the files?
Like by, date modified, size, name, etc?
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
-
Nov 22nd, 2001, 01:53 AM
#19
Conquistador
can't test it, but you should be able to load it into an array then sort the array...
-
Nov 22nd, 2001, 09:29 AM
#20
PowerPoster
how would i load it into an array?
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
-
Nov 23rd, 2001, 02:40 PM
#21
PowerPoster
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
-
Nov 23rd, 2001, 07:16 PM
#22
Conquistador
I think it's pretty difficult
I will have heaps of free time in a week, i'll figure something out, so just PM me. after thursday - (no more exams )
-
Nov 23rd, 2001, 09:36 PM
#23
PowerPoster
Alright, i'll remember.
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
-
Nov 23rd, 2001, 10:09 PM
#24
Conquistador
good for you
i think it would be quite difficult
can't remember if php can handle multiple dimension arrays
-
Nov 23rd, 2001, 11:37 PM
#25
PowerPoster
that would be bad if it didn't. it would certainly make things difficult
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
-
Nov 24th, 2001, 01:25 AM
#26
Conquistador
i was thinking though
It could be put into a normal array, depending on what order they want
i.e.
By FIlename
then the string =
"filename, size, " etc
By size
then the string =
"size, filename, " etc
then you sort the array
and split it
-
Nov 24th, 2001, 11:49 AM
#27
PowerPoster
sounds good. i still have no idea how to do it though.
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
-
Nov 27th, 2001, 04:27 AM
#28
Conquistador
here you go.
hope that works.
PHP Code:
<?
$dir_name = "./";
$dir = opendir($dir_name);
$myint = -1;
while ($file_name = readdir($dir))
{
if (($file_name != ".") && ($file_name != "..") && !is_dir($file_name))
{
$myint++;
$file_list[0][$myint] = "$file_name";
$file_list[1][$myint] = filesize($file_name);
$file_list[2][$myint] = filemtime($file_name);
}
}
//asort($file_list[0]); Sort by filename
//asort($file_list[1]); Sort by filesize
//asort($file_list[2]); Sort by modified time
asort($file_list[1]);
while (list($key) = each($file_list[1])) {
print
$file_list[0][$key].",".$file_list[1][$key].",".$file_list[2][$key]."<br>";
}
?>
-
Nov 27th, 2001, 06:38 PM
#29
Thread Starter
Fanatic Member
The only part that works is the file size part. And, the filename and date parts print in the same order.
Last edited by Wynd; Nov 27th, 2001 at 06:43 PM.
Alcohol & calculus don't mix.
Never drink & derive.
-
Nov 27th, 2001, 06:47 PM
#30
Thread Starter
Fanatic Member
Nm, got it to work. I have been looking for this for a long time. Thanks for the help!
Alcohol & calculus don't mix.
Never drink & derive.
-
Nov 28th, 2001, 01:53 AM
#31
Conquistador
No probs, what was the problem?
Did you quote the message and then copy that source or what?
-
Nov 28th, 2001, 06:23 PM
#32
Thread Starter
Fanatic Member
I just c&p'ed ity from the web page. In this part:
PHP Code:
each($file_list[1])
you need to change "1" to 0, 1, or 2 depending on what you want.
Alcohol & calculus don't mix.
Never drink & derive.
-
Nov 29th, 2001, 03:01 AM
#33
Conquistador
oh yeah, woops i should've mentioned that in my other post :|
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|