Results 1 to 8 of 8

Thread: dynamic directory update with links

  1. #1
    Join Date
    Sep 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cool dynamic directory update with links

    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

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    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.

    Code:
    <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.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Sep 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default thank you

    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.
    Last edited by fcopcf89; 09-18-2007 at 12:24 AM.

  4. #4
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Change this:

    Code:
    if ($file != '.' && $file != '..' && !is_dir($file) && $file != $_SERVER['PHP_SELF']) {
    to this:

    Code:
    if ($file != '.' && $file != '..' && !is_dir($file) && !strstr('filename_here.php', $file)) {
    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  5. #5
    Join Date
    Mar 2008
    Location
    Phoenix, AZ
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Exclamation Can this be used in a different folder?

    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.

  6. #6
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Yes, simply change the highlighted part to the path of the new directory in relation to the script.

    Code:
    <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.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  7. The Following User Says Thank You to thetestingsite For This Useful Post:

    activenets (03-19-2008)

  8. #7
    Join Date
    Mar 2008
    Location
    Phoenix, AZ
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Thank you!

    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.

  9. #8
    Join Date
    Jun 2007
    Posts
    543
    Thanks
    3
    Thanked 78 Times in 78 Posts
    Blog Entries
    1

    Default

    you can modify my dir script here.
    [Jasme Library (Javascript Motion Effects)] My Site
    /\/\@§†ê® §©®¡þ† /\/\@|{ê®
    There are 10 kinds of people in the world, those that understand binary and those that don't.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •