scandir
returns filenames, not pathnames, so you need to add the directory prefix:
foreach(scandir('files'. $dir) as $filename){
if($filename == ".." || $filename == "."){
// do nothing. We want files and folders, not dots.
}
else
{
if(is_file($filename)){
echo '<a href="files/'. $dir . '/' . $filename .'">'. $filename .'</a><br>';
}
else
{
echo '<a href="files.php?dir=' . $dir . '/' . $filename .'">'. $filename .' (dir)</a><br>';
}
}
}
You were also missing files.php?
in the first link, and the second link should use dir=
to make it recurse into the subdirectory.