Solved

List directory files in html table

Posted on 2004-03-26
2
359 Views
Last Modified: 2008-02-01
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
Comment
Question by:mesonas
2 Comments
 
LVL 2

Accepted Solution

by:
aabbas earned 250 total points
ID: 10688179
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
 

Author Comment

by:mesonas
ID: 10688275
Just what I wanted ! Thanks !
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now