Jump to content

How do I list files and folders with description?


dktekno

Recommended Posts

I have a folder, named "/filemetadata"

 

In that folder, I have some files, html, jpg etc.

 

I also have an index.php

 

In index.php I have a script that lists files and folders.

<?php
$path = "/filemetadata";
$dh = opendir($path);
print "Directories <br>************************* <br>";
  while (($dir = readdir($dh)) !== false) {
      if ( $dir != "." && $dir != ".." ){
          $file = @fopen("$path/$dir", "r");
                if (!$file){
                    print "<a href='$dir'>$dir</a><br>";
                }
      }
  }
closedir($dh);

$path = getcwd();
$dh = opendir($path);
print "<br>Files <br>************************* <br>";
  while (($dir = readdir($dh)) !== false) {
      if ( $dir != "." && $dir != ".." ){
          $file = @fopen("$path/$dir", "r");
                if ($file){
               
                    print "<a href='$dir'>$dir</a><br>";


                }
      }
  }
closedir($dh);
?>

 

 

Try it out, and as you can see, files and folders are listed.

 

Now, here is the task:

 

I have a MySQL database and a table "filemetadata". In this table, I have 2 TEXT-fields, one called "filename" and "description".

 

Not all files listed have a description in the database. Only those registered in the database.

When I register a file in the database, along with a description of that file, I enter the file name in the field "filename". By file name I mean the WHOLE path, like c:\filemetadata\myfile.exe

 

And the description of the file is in "description".

 

What I want it to do is that, when the script has found a file, and is going to write it in the list of files, it search for that particular file name in the database, and see if it can find that file name in the field "filename" in my table "filemetadata".

 

If it has found the filename, it will take its corresponding description and place it underneath the file name in the list.

Like this:

 

([ and ] tells that this is a hyperlink to a file or folder).

-----

 

Directories

*************************

[folder_with_files]

 

Files

*************************

[index.php]

Here I have a description.

 

[a_php_file.php]

Here I have another description.

 

[Text_document.txt]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.