Forum Moderators: coopster

Message Too Old, No Replies

Directory links

         

welshandy

11:31 am on Feb 9, 2009 (gmt 0)

10+ Year Member



Can someone tell me what to add to this code so it will show the contents of a directory as clickable links. For example, to download flv or jpeg

<?
$dir = "images/"; //you could add a $_GET to change the directory
$files = scandir($dir);
foreach($files as $key => $value){
echo $value; //you could add an icon in here maybe, a link to the file/directory, or a link to list files in that directory
}
?>

Thanks
Welshandy

PHP_Chimp

11:36 am on Feb 9, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



echo "<a href=\"$value\">$value</a>";

echo is printing html, so to get a link you just need to enclose your $value in an anchor tag.

welshandy

12:03 pm on Feb 9, 2009 (gmt 0)

10+ Year Member



Thank you that was a very quick response and it's much appreciated.

Welshandy