View Full Version : dynamic directory update with links
fcopcf89
09-15-2007, 01:12 PM
I am not even sure if the title is correct, but here is what I want to do, and I am not sure how to go about it.
I run a website for our fire department and i want to set up my Public information officer to be able to upload files (i.e press releases that are time sensitive), and have a page that will automatically display a link for the file he uploads with the title of the file, the date and time modified.
Basically showing a list of all the files in the directory (being that his files will be the only one in that directory) so that the media can pull past updates also.
Java, DHTML, PHP? I am not sure where to even start. I have found scripts to do smoething similar for photos, but not for files (such as word or excel documents).
Any help would be wonderful. Thank you in advance.
Fcopcf89
www.fresnocountyfire.net
thetestingsite
09-15-2007, 02:30 PM
Your best bet would be PHP or any other server side language that can access the file system on the server. You said you found a script for images, if you post it here we can modify it to work with word/excel documents. Here is just a simple script that you could use as well.
<table>
<tr>
<td>Document</td>
<td>Date/Time Modified</td>
</tr>
<?php
$files = array();
if (is_dir('.')) {
if ($dh = opendir('.')) {
while (($file = readdir($dh)) !== false) {
if ($file != '.' && $file != '..' && !is_dir($file) && $file != $_SERVER['PHP_SELF']) {
$files[] .= $file;
}
}
closedir($dh);
}
}
foreach ($files as $theFile) {
?>
<tr>
<td><a href="<?php echo $theFile;?>"><?php echo $theFile;?></a></td>
<td><?php echo date ("F d Y H:i:s.", filemtime($theFile));?></td>
</tr>
<?php
}
?>
</table>
Simply, place the above script in the directory you wish to index. It will do the rest.
Also; if your server is using Apache, it has the ability to index all of the files in that directory without the need for any other script.
Hope this helps.
fcopcf89
09-18-2007, 12:08 AM
That is right along the lines of what I want to do. Thank you very much. Now if i can figure out how to get it to not display the .php file in the directory and sort by most recent file, that would be perfect. Thank you again.
thetestingsite
09-18-2007, 12:19 AM
Change this:
if ($file != '.' && $file != '..' && !is_dir($file) && $file != $_SERVER['PHP_SELF']) {
to this:
if ($file != '.' && $file != '..' && !is_dir($file) && !strstr('filename_here.php', $file)) {
Hope this helps.
activenets
03-19-2008, 02:58 PM
I love your script that displays the contents of a folder on the server. I have one question though. Can the php script be placed in a folder OTHER than the one containing the files that are desired to be displayed? I like the script, but would like to show files in a folder where users will be deleting some of the files via ftp. I would not want the php script deleted too. :)
thetestingsite
03-19-2008, 03:00 PM
Yes, simply change the highlighted part to the path of the new directory in relation to the script.
<table>
<tr>
<td>Document</td>
<td>Date/Time Modified</td>
</tr>
<?php
$files = array();
if (is_dir('.')) {
if ($dh = opendir('./path/to/folder')) {
while (($file = readdir($dh)) !== false) {
if ($file != '.' && $file != '..' && !is_dir($file) && $file != $_SERVER['PHP_SELF']) {
$files[] .= $file;
}
}
closedir($dh);
}
}
foreach ($files as $theFile) {
?>
<tr>
<td><a href="<?php echo $theFile;?>"><?php echo $theFile;?></a></td>
<td><?php echo date ("F d Y H:i:s.", filemtime($theFile));?></td>
</tr>
<?php
}
?>
</table>
Hope this helps.
activenets
03-19-2008, 05:06 PM
Thank you so much for the update to the script! It seems to be attempting to work but delivers an error with the directory. The script is located in a folder called "client21" and the files to display are in a folder beneath called "files" (client21/files). I set the line in the script to read: "if ($dh = opendir('./files')) {" When run it returns the following: Document Date/Time Modified CPUInfo.txt Warning: filemtime() [function.filemtime]: stat failed for CPUInfo.txt in /home/pinnacle/public_html/clients/client21/files.php on line 36
December 31 1969 19:00:00.
This error occurs after every file displayed. :confused:
Master_script_maker
03-19-2008, 09:21 PM
you can modify my dir script here. (http://masterproject.freehostia.com/page=dir)
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.