using exec() to produce a directory listing. probably the shortest code to
produce a full file-list without resorting to the servers built in directory
display
“directory list with exec” makes use of the built-in PHP functions
exec( ).
01<?php 02 03/* 04 05this function takes advantage of the servers operating system an therefore only 06works on a "real server", means *nix based machines 07 08the following options are available 09(i stripped a few which do not make sense for use with PHP): 10 11-A List all entries except for . and ... Always set for the super- 12 user. 13 14-F Display a slash (`/') immediately after each pathname that is a 15 directory, an asterisk (`*') after each that is executable, an at 16 sign (`@') after each symbolic link, an equals sign (`=') after 17 each socket, a percent sign (`%') after each whiteout, and a ver- 18 tical bar (`|') after each that is a FIFO. 19 20-L If argument is a symbolic link, list the file or directory the 21 link references rather than the link itself. This option cancels 22 the -P option. 23 24-P If argument is a symbolic link, list the link itself rather than 25 the object the link references. This option cancels the -H and 26 -L options. 27 28-R Recursively list subdirectories encountered. 29 30-S Sort files by size 31 32-T When used with the -l (lowercase letter ``ell'') option, display 33 complete time information for the file, including month, day, 34 hour, minute, second, and year. 35 36-a Include directory entries whose names begin with a dot (.). 37 38-c Use time when file status was last changed for sorting or printing. 39 40*/ 41 42// we use "." - means the current directory 43$directory='.'; 44 45exec('ls -al '.$directory,$directory_list); 46 47/* 48 49when you use the -l flag w/ ls, there will be a string of characters on the left 50for each file, which may look something like -rwxr-xr-x 51 52the first character describes what the item is: 53- = regular file 54d = directory 55b = special block file 56c = special character file 57l = symbolic link 58p = named pipe special file 59 60example: lrwxr-xr-x would be a symbolic link 61 62the next 9 characters are 3 groups of 3 characters each, which tell the 63read/write/execute permissions for user, group, and other respectively: 64 65r = read 66w = write 67x = execute 68 69using the above example of lrwxr-xr-x, you would have symbolic link file, where 70the user can read, write and execute (rwx), and the group and others 71can read and execute (r-x) 72 73*/ 74 75echo' 76<p>content of "'.$directory.'/"</p> 77<ul>'; 78foreach($directory_listas$file) 79{ 80echo' 81 <li>'.$file.'</li>'; 82} 83echo' 84</ul>'; 85 86?>