<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>Files in Directory</title>
</head>
<body>
<?php
echo("<h1>opendir</h1>");
$path = "pub/"; // "" current directory
if ($handle = opendir($path)) {
while (false !== ($entry = readdir($handle))) {
if(is_dir($entry)) {
echo "DIR: $entry<br>";
} else {
echo $entry. filesize($path.$entry)."<br>";
}
}
closedir($handle);
}
echo("<hr>");
echo("<h1>glob</h1>");
$path = "*.*";
foreach (glob($path) as $filename) {
echo "$filename size " . number_format(filesize($filename)) . "<br>";
}
echo("<hr>");
echo("<h1>scandir(path), array('.', '..'))</h1>");
$path = ".";
$files = array_diff(scandir($path), array('.', '..'));
foreach ($files as $file) {
if(is_dir($file)) {
unset($files[$file]);
echo(">> $file - dir<br>");
}
}
for ($i=2 ; $i < count($files) ; $i++) {
if (!(is_dir($files[$i])))
echo $files[$i]."<br>";
}
?>
<br>
</body>
</html>