views:

85

answers:

5

I am redesigning my company's intranet site in Wordpress and one of the things they need is an archive of company memos. There are over 300 memos saved in one location and I'm wondering if there is a jQuery script that I can run that will read the contents of a local (network) folder and auto-generate a list of the contents of that folder dynamically (and generate those names as a hyperlink to that file, but if I can list the files, I can get include the hyperlink tag myself).

I can always manually create the list of hyperlinks (would take a couple days to do so) but if I can generate it dynamically, whenever a new memo is added, the script will automatically include it making the site much easier to maintain.

Is this at all possible?

I know that this can probably be done in PHP, but the page I need to do this on is not a php page, it is one of the subpages that is created in wordpress that does not have a php file extension and can't run php code (that I know of)

Thanks in advance for any and all assistance.

+2  A: 

jQuery will run on the viewer's browser, and therefore cannot see any files or folders or network shares. Javascript is not allowed filesystem access. You will need to do this from the server's end, and that usually means within the file (as you said PHP). Any webserver could do it, you dont even have to use wordpress, just try linking directly to the folder and Apache or IIS should construct an index page.

Karl
+1 for *linking directly to the folder*. Keep it simple.
Gordon
A: 

Karl is right, the best way to do it is in a server side programming language.

However if you still want it in JS, you could use ActiveX, to my knowledge it will work only in IE and you will have to overcome some security boundaries.

CodeProject tutorial

Alexandru Luchian
+3  A: 

A quick way to do this is to use one of Apache httpd's core features and modify the configuration file httpd.conf to include the "Indexes" keyword in a "Directory" entry like this:

<Directory /var/www/html/company/memo/folder>
   Options Indexes FollowSymLinks
</Directory>

This will cause a directory listing of files to be shown with links generated to any of the files, and grant access based on the file permissions. Restart your web server after you make the change, and you are good to go.

Vernon
A: 

You might have better luck on the WP forums, but between the Exec-PHP plugin and PHP5's scandir, you ought to be able to get something together. (check out the user comments on the scandir page too. Especially if you're stuck with PHP4)

Andy Ford
+1  A: 

Here is an example. Obviously change the directory you are going to want to open, and instead of alerting the results, you can populate a div or page or whatever you need.

<?php
if($_POST['list']){
    if($handle = opendir('.')){
        echo "Directory handle: $handle\n";
        echo "Files: \n";
        while(($file = readdir($handle))!=false)echo "$file\n";
    }
    closedir($handle);
    exit;
}
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
        <script type="text/javascript" src="include/js/jQuery/jquery-1.4.1.min.js"></script>
        <script type="text/javascript">
            $(document).ready(function(){
                jQuery.post('test.php?', {list: 1}, function(response){
                    alert(response);
                    });
            });
        </script>
    </head>
    <body>
    </body>
</html>
caligoanimus
Thanks for the responses guys. I'll give it a shot and see what I can come up with.