AZForums: [PHP] Show Every File/Directory in a Directory - AZForums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

[PHP] Show Every File/Directory in a Directory

#1 User is offline   Rokan Icon

  • :)
  • PipPipPipPipPipPipPipPipPipPip
  • View blog
Group:
+ Legendary
Posts:
6,600
Joined:
29-August 05

Post icon  Posted 09 May 2007 - 09:03 PM

You can find a demo of the script here.

Same as usual. Open up notepad, or another text editor, and save this code as a .php file:

Quote


<html><head>
<style type='text/css'>
#dirlist { background: #ffffff; }
#file { background: #f6f6f6; }
</style>
</head>
<body>
<?php
//write to files before loading them

//needs adding

//function creation
function DirList($dir,$align) {
echo "<table align='$align' width='80%'>";
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$link = $dir."/".$file;
$i++;
if(is_dir($dir."/".$file)) {
echo "<tr><td id='dirlist' align='left'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>Directory '$link'</b></td></tr>";
echo "<tr><td id='dirlist' align='left'>"; DirList($link,$align); echo "</td></tr>";
continue;
} else {
echo "<tr><td align='left' id='file'>&nbsp;&nbsp;&nbsp;<a href=\"$link\">$link</a> - ".filesize($link)." bytes.</td></tr>";
}
}
}
if($i <= 0) {
echo "<tr><td align='left' id='file'>&nbsp;&nbsp;&nbsp;-- Folder is empty --</td></tr>";
}
closedir($handle);
}
echo "</table>";
}

DirList(".","center");

?>
</body>
</html>


Almost none of it is editable, as it creates a function. No variables are stored in the function that can be used with other purpose - functions return one value only. That value in this case is every single file and directory in the list. I also skinned it a little.

To change the directory you are looking at, you must change this part:
DirList(argument0,argument1);


argument0 - the directory you look at. "." would display every file in the current directory. "./images/" would display all files in the images folder.
argument1 - the alignment of the display on the screen.
0

#2 User is offline   Mintty Icon

  • AZ Mastermind
  • PipPipPipPipPipPipPipPipPip
Group:
+ Legendary
Posts:
3,851
Joined:
28-December 06

Posted 09 May 2007 - 09:59 PM

Ah, work great, I may use this, great code :D
Posted Image
Sig by Mitch

Posted Image
0

#3 User is offline   BlackAngel Icon

  • The Dark Angel, Raven
  • PipPipPipPipPipPipPipPipPipPipPipPip
Group:
+ Legendary
Posts:
23,625
Joined:
29-August 05

Posted 09 May 2007 - 10:06 PM

Like Dawg said, this is a great code.
Boost #2 | GOTM #3 | GOTM #3 | LOTW #19 | MOTW #31 | SOTW #43 | Friendliest EOTY
Posted Image
{M e s s a g e me} - my P r o f i l e - {AZ Rules} - Q u e s t i o n Me - {the M y s p a c e}
{{K I N G D O M}} {{H E A R T S}}
Msn: poprock.explosion@live.com

0

#4 User is offline   Rokan Icon

  • :)
  • PipPipPipPipPipPipPipPipPipPip
  • View blog
Group:
+ Legendary
Posts:
6,600
Joined:
29-August 05

Posted 09 May 2007 - 10:42 PM

Demo -- Click


:classic:
0

#5 User is offline   cipcip Icon

  • AZ Mastermind
  • PipPipPipPipPipPipPipPipPip
Group:
Members
Posts:
2,624
Joined:
19-November 06

Posted 11 May 2007 - 04:35 PM

great stuff ... thanks for sharing!
0

#6 User is offline   Rokan Icon

  • :)
  • PipPipPipPipPipPipPipPipPipPip
  • View blog
Group:
+ Legendary
Posts:
6,600
Joined:
29-August 05

Posted 11 May 2007 - 07:41 PM

Your welcome cipcip. It seems like php is the thing im good at right now, so i'd best make the best of it.
0

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users