• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 417
  • Last Modified:

List directory files in html table

I have a postgresql database with records that have files associated wich i intend to keep in a directory related to this record. Ex. record with id=1 will be in " var/www/html/1/ " .
What i want is to list all files related do the current record that are in the directory and give the oportunity to ther user to remove or make file upload.
0
mesonas
Asked:
mesonas
1 Solution
 
aabbasCommented:
Try the following and you will get a list of all the files in the selected directory.

<?php
// ... assuming that you already have the database connection and the ID value in $v
// following lines will read the filenames from the directory and list in a table.

if ($handle = opendir('/var/www/html/$v/.')) {
  echo "<table>";
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") {
            echo "<tr><td>$file</td></tr>\n";
        }
    }
    closedir($handle);
  echo "</table>";
}
?>

Hope, it will help.

Best of luck.
0
 
mesonasAuthor Commented:
Just what I wanted ! Thanks !
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now