The process goes pretty much like this: open a directory, read the directory in a loop, check each entry to see if it is a file or directory, display each accordingly, then close the directory.
The first step is to open the directory using the opendir function which accepts a string representing the path and returns a handle if successful.
Code: Select all
$dir = '/path/to/your/files/';
if($dh = opendir($dir)) {
}
Code: Select all
$dir = '/path/to/your/files/';
if($dh = opendir($dir)) {
while(($file = readdir($dh)) !== false) {
}
closedir($dh);
}
Code: Select all
$dir = '/path/to/your/files/';
if($dh = opendir($dir)) {
while(($file = readdir($dh)) !== false) {
if($file != '.' && $file != '..') {
}
}
closedir($dh);
}
Code: Select all
$dir = '/path/to/your/files/';
if($dh = opendir($dir)) {
while(($file = readdir($dh)) !== false) {
if($file != '.' && $file != '..') {
if(is_dir($dir . $file)) {
echo "<div> - " . $file . "</div>\n";
}
else {
echo "<div>" . $file . "</div>\n";
}
}
}
closedir($dh);
}