0

I can't work out how to write a PHP script that will iterate over a set of files in a folder (let's say, 3 MP3 files), output the filename and add anchor tags around this to provide a download link.

I assume this is how I would begin but I have no idea where to go.

$dir = opendir("Z:\\uploads\\");  
while ($name = readdir($dir)) {
Popnoodles
  • 28,090
  • 2
  • 45
  • 53

1 Answers1

1
$dir= opendir("Z:\\uploads\\"); 
echo '<ul>';
if ($handle = opendir($dir)) {
    while (false !== ($fn = readdir($handle))) {
        echo '<li><a href="'.realpath($dir.$fn).'">'. basename($fn).' </a></li>';
    }
    closedir($handle);
}
echo '</ul>';
Popnoodles
  • 28,090
  • 2
  • 45
  • 53