954,604 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Making link with variable

Ok, I am working on a website which will accept uploads and in an iFrame next to the upload form display a list of files in the upload folder. The iFrame will be showing a php script that is listing the files. Here is where the problem is, I can list the files without a problem, however I would like to make each file name a link to download said file. This is where I am having trouble. The php code that is supposed to list the links is below.

<?php 
if ($handle = opendir('tpl')) {
    while (false !== ($file = readdir($handle))) { 
        if ($file != "." && $file != ".." && $file != ".DS_Store" && $file != "list.php") { 
            echo (<"a href=\"tpl/". $file ."\">$file</a>"); 
        } 
    }
    closedir($handle); 
}
?>

What I would like to do is make the file name a link, but the link needs to have the variable in it.
Just an f.y.i. the folder with all the files in it is "tpl" and the name of this php file is "list.php".


Thanks in advance

nyra98
Newbie Poster
2 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

Try the following:

foreach (glob("tpl/*") as $filename) {
    echo "<a href=\"$filename\">".basename($filename).'</a>';
}
cwarn23
Occupation: Genius
Team Colleague
3,033 posts since Sep 2007
Reputation Points: 413
Solved Threads: 259
 

That worked, thanks!

nyra98
Newbie Poster
2 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: