DO I really need to use closedir() to close the directory????
what happens if i don't close it?????
Code: Select all
<?php
if ( $dir = opendir(".") ){
while (false !== ($file = readdir($dir)) ){
if ( $file != "." && $file != ".." ){
if ( is_file($file) ){
$files[] = $file;
}
else {
$dirs[] = $file.'/';
}
}
}
if($dirs) {
natcasesort($dirs);
foreach($dirs as $dir) {
$dir = trim($dir, "./");
echo '<tr><td class="subtitle">'.$dir.'</td></tr>';
}
}
if($files) {
natcasesort($files);
foreach ($files as $file) {
echo '<tr><td><a href="'.$dir.'/'.$file.'">'.$file.'</a></td></tr>';
}
}
// closedir($dir); <---- see, if i use it I always get an argument error. so i tried it without the closedir() and it works just fine. but i don't know if that safe or not.
}
?>