Basically, I've been researching this for about a week now and have only been able to find a handful of not-so-useful articles. I don't know if what I want to do is even possible, but I want to ask here as the advice around these parts has always been top-notch. Here's what I want to do.

I'd like to have a directory on the server where people can place documents. These would be in a share and everyone would have root server access since I am operating on an intranet. On my website, I'd like to have a page that lists all the files within said directory and makes them available for downloading. Simply, it's a small little document repository, dynamically created using PHP.

The few suggestions I've seen revolve around using MS's Index Server for this, and while I have seen a couple code examples, nothing has come close to what I am looking for.

First off, is what I am looking to do possible? Can I have a page dynamically list the files in a directory and make them available for download?

Second, if possible, could someone point me in the right direction?

Any help would be greatly appreciated.

    Off the top of my head, I can see two ways of doing this:

    1. Stick all of the files into a directory under the web server root. Depending on what permissions you have set for that directory, when someone puts in that directory path in their browser, it should just list all contents in that directory. It's not "dynamic", but if all you want to do is have a repository of files, that should do. Very similar to when you go to an FTP server and see a list of files for download. Depending on what browser they are running, a user could "righ-click" and do a "save target as" to save the file locally. Either that or you could actually have FTP running on your server if you want to deliver documents that way.

    2. If you choose to do it where you provide links to the filenames and it has to be "dynamic", then putting the links in a column of a database would work. Then when your PHP pages loads, it will run a query to grab everything from the the "links" column of your table. In a nutshell, these links are paths to where the files are stored. The advantage of the database approach is that you can use PHP to limit the number of results to be displayed per page, log click-throughs to the links, etc.

    As for downloading the files, look into using the header() function and setting the MIME type, Content-Type, Content-Length.

      Thanks for the tips Rachael, but it's not quite what I am looking for. Let me be a little more clear.

      I am working on an intranet, and the users will place files in a seperate network drive, let's call it the X: drive. What I would like to do is have a page that builds a list of the file names that reside in particular directory in the particular drive. This is why is suspect the index server will become a player in my solution.

      I know it's going to be complex, but it's been requested of me so I need to give it a go.

        Maybe I'm not understanding clearly... why wouldn't the second suggestion I gave you not work?

          In your second suggestion, I'm not sure how your suggesting the links get into the database. I guess that's the challenge, getting the filenames to get into the database automatically so they can appear on the page.

          I've seen this done with ASP numerous times.

            If you're using MS database products, I would have to refer you to the PHP manual for the correct APIs as I've only worked with MySQL where PHP is concerned. For your INSERT, though, in a basic situation, it would look as follows:

            <?php
            $file = "c:\\directory\\sub\\file.txt";
            
            $sql = "INSERT into Table
                        (file_link)
                         VALUES
                         ('$file')";
            ?>
            

            Once you have that path in a column of a database, you just use a SELECT query to pull records out of the db and then present it in your web pages. I am not very sure what Index Server is, but major databases (to my knowledge) have the ability to index columns, so maybe it would save your company money not to purchase a license for the product and just rely on the indexing features of your db of choice.

            HTH.

              I think we're talking about two different things Rachel 🙂

              Index Server is a component of IIS, which is the web server they are using here. Basically, it indexes all of it's contents for searching and directory listings, etc...

              Writing an SQL statement to populate a table with the filenames isn't a problem. I wish it were that simple, but things needs to be automatic. Let me lay it out again.

              -On the Intranet here in our company, everyone has access to a shared network drive. It has been requested that a directory be created on the drive where people can place documents for viewing and downloading by other users.

              -I would like to create a page within my site that sees what files are in the shared network drive (not a web directory) and populates a page with the contents. when a new document is placed in the directory, it appears on the page.

              -I would then like users to be able to view these documents by clicking on them.

              As I said, it's been done with ASP, but I suspect it's easier, due to the MS connection between it and IIS/Index Server. I am looking for a PHP solution, and while I'm fairly sure it's possible, my search hasn't been very fruitful

                Originally posted by Spire2000
                -On the Intranet here in our company, everyone has access to a shared network drive. It has been requested that a directory be created on the drive where people can place documents for viewing and downloading by other users.

                You can do this. HTML will permit you to upload files and PHP can be used to move the uploaded file to a permanent location on your server:
                http://www.php.net/features.file-upload
                To move the file to a permanent location:
                http://www.php.net/move_uploaded_file
                Once the file is at it's permanent location, do an INSERT into your db stating the path (as I showed in my previous post).

                -I would like to create a page within my site that sees what files are in the shared network drive (not a web directory) and populates a page with the contents. when a new document is placed in the directory, it appears on the page.

                This is a query of your db where it will retrieve all filenames/paths of what you have uploaded to that directory.

                -I would then like users to be able to view these documents by clicking on them.

                This depends on the browser. If the browser supports viewing Word documents, for example, the browser can view it. Else, the user will be prompted to download.

                  Not being that familiar with IIS, and even less so with Index Server (beyond I forget the exploit), my suggestion is pretty basic - it's based on something I cobbled together for another IIS-drive site, but would work pretty much anywhere (though wouldn't really be necessary on Apache, since that already supplies this):

                  Assuming that the web server can see the directory or drive at all (reasonable, otherwise downloads would be difficult), one could read through the directory and see what files it contains, listing them by name. It could also operate recursively, to allow a tree-like directory structure to be maintained. It started with [man]opendir[/man]. I also looked at file extensions and supplied suitable icons when available.

                    Write a Reply...