Php Directory Listing Program 05.07.08
I basically want a small php program that will list the files in a directory out, but allow me to add a very small comment to them in the display.
The project will contain only 2 files, index.php and admin.php files written which do the following:
it will list all the items in a directory filtered by extention that I allow like:
$homedir = ‘/home/john/’;
$filetypes = array (’pdf’,'jpg’,'gif’,'png’,'doc’);
This will only list these 5 types of files in /home/john.
files that start with a . will not be listed.
The index.php program will read through the entire directory, SHA1 all the files, and then list a small description.
database will basically have 3 items in it:
filename (varchar(50)),
SHA1 (varchar(40)),
Comment (varchar(500))
Examples:
somefile.doc
2fd4e1c67a2d28fced849ee1bb76e7391b93eb12
This is a doc file that I want you to read
solefile2.pdf
de9f2c7fd25e1b3afad3e85a0bd17d9b100db4b3
This is the sales report.
The filenames of course will link to the file itself and allow for download.
When a file is uploaded or copied to that directory, index.php will know that this was not added by doing a comparison, and then adding it to the database. To speed up this process, a simple ls will be taken when it runs, and compared to the db.
admin.php allows 2 functions:
1) Renaming the file which will rename the name of the file in the directory and update the db.
2) Adding a comment.
All newly uploaded have no comments.
Because it’s possible that 2 files with 2 names still have the same hash value because they have the same content, each file is treated unique as is the associated comment.
Renaming a file will not change the hash of the file so the comment stays, but if there’s an upload that overwrites the file and thus has a different hash value, index.php should do garbage cleanup on the database and remove that entry.
admin.php should simply list filename and comment area in a thin webform per row.
admin.php requires some sort of login/password to access.
database name and SHA1(admin password) can be stored in a .config file.
That’s it. I think this can be done easily in 2 hours by someone competent.
I’ve attached a mockup of what I want.



