Can anyone tell me what's wrong with the following?
echo "<a href="index.php?currentpage=viewitem&item=$filename">"
yes... you finish a string when you don't intend to. Read up on strings in the PHP manual:
Strings
Try this:
echo "<a href=\"index.php?currentpage=viewitem&item=$filename\">"
or
echo '<a href="index.php?currentpage=viewitem&item=$filename">'