Search code examples
phpglob

How to wrap echoed file name in <a> tag?


I am having trouble figuring out how to make text found using glob into a link. I am sure it is something really simple, such as adding an <a> tag to the echo line, but I cannot figure out where in the code to put this.

Here is my current code:

 $directory = "*.xls";
 $directory = (!strstr($directory,"*") || $directory =="./" ) ? $directory."*" : $directory;
 $files = glob($directory);
 for( $i=0; $i < sizeof( $files); $i++)
 {
     echo basename($files[$i])."<br/>\n";
 }

Solution

  • Try this:

    $file = basename($files[$i]);
    echo '<a href="' . $file . '">' . $file . '</a>' . "<br />\n";