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

Recommended Answers

All 2 Replies

Try the following:

foreach (glob("tpl/*") as $filename) {
    echo "<a href=\"$filename\">".basename($filename).'</a>';
}

That worked, thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.