Directory listing

 
Post new topic   Reply to topic    Aprelium Forum Index -> PHP
View previous topic :: View next topic  
Author Message
Flux
-


Joined: 13 Oct 2006
Posts: 48

PostPosted: Mon Feb 12, 2007 9:57 am    Post subject: Directory listing Reply with quote

Pretty standard, right?
So I've tried to use a directory script with a $_GET so that I can just define what directory in a querystring. But anything other than the folder the script file (I named it dir.php) is in, and it gives me a:
Warning: opendir("<whatever directory i try to open>") [function.opendir]: failed to open dir: Invalid argument in F:\dir.php on line 6.

Here's my entire script:
Code:
<?php
// directory path can be either absolute or relative
$dirPath = $_GET['dir'];

// open the specified directory and check if it's opened successfully
if ($handle = opendir($dirPath)) {

   // keep reading the directory entries 'til the end
   while (false !== ($file = readdir($handle))) {

      // just skip the reference to current and parent directory
      if ($file != "." && $file != "..") {
         if (is_dir("$dirPath/$file")) {
            // found a directory, do something with it?
            echo "[$file]<br>";
         } else {
            // found an ordinary file
            echo "$file<br>";
         }
      }
   }

   // ALWAYS remember to close what you opened
   closedir($handle);
}
?>


Is there any file permission setting I have to change?...because I can do anything with the files and folders on my server EXCEPT see them on an automatically generated webpage.
Also, if/when this is solved, how does one add the url to the file or directory corresponding to it?

Ideally, I want this to work just like the "Standard Directory Listing" provided with Abyss Web Server, but the problem is that I would like to add in a necessity to log in, and be able to use a universal database (In my case, a MySQL database) which is why I'm working with php for a directory listing script.

Of course, if anyone knows of any script available from someone who already duplicated Abyss' directory listing ability in a .php file, please direct me to it.
_________________
My signature is so lame.

I think phpBB forums hates my laptop '.';
Back to top View user's profile Send private message
aprelium
-


Joined: 22 Mar 2002
Posts: 6800

PostPosted: Mon Feb 12, 2007 3:21 pm    Post subject: Re: Directory listing Reply with quote

Flux,

The parameter sent to opendir() should be a full directory path (on Windows it should look like C:/test/dir1/dir2).
_________________
Support Team
Aprelium - http://www.aprelium.com
Back to top View user's profile Send private message Send e-mail
Flux
-


Joined: 13 Oct 2006
Posts: 48

PostPosted: Mon Feb 12, 2007 9:24 pm    Post subject: Reply with quote

Meaning that if I use the same script that i posted up before, I should have a url:
http://site.com/dir.php?dir="F:\files\"
If I want to browse the equivalent of http://site.com/files/ ?
Or is it just:
http://site.com/dir.php?dir="/files/" ?

It does, at least, open up the directory that the script file is located in...
_________________
My signature is so lame.

I think phpBB forums hates my laptop '.';
Back to top View user's profile Send private message
aprelium
-


Joined: 22 Mar 2002
Posts: 6800

PostPosted: Tue Feb 13, 2007 11:28 am    Post subject: Reply with quote

Flux,

You script as it is written requires that you call it using something like http://site.com/dir.php?dir=F:\files\ . If you need a better way to enter paths, you'll have to tweak your code.
_________________
Support Team
Aprelium - http://www.aprelium.com
Back to top View user's profile Send private message Send e-mail
pkSML
-


Joined: 29 May 2006
Posts: 955
Location: Michigan, USA

PostPosted: Tue Feb 13, 2007 11:36 pm    Post subject: Re: Directory listing Reply with quote

Flux wrote:
Of course, if anyone knows of any script available from someone who already duplicated Abyss' directory listing ability in a .php file, please direct me to it.


http://stephen.calvarybucyrus.org/code/3
Just take out the first 12 or so lines (first PHP code block).
_________________
Stephen
Need a LitlURL?


http://CodeBin.yi.org
Back to top View user's profile Send private message Visit poster's website
Flux
-


Joined: 13 Oct 2006
Posts: 48

PostPosted: Wed Feb 14, 2007 12:45 am    Post subject: Reply with quote

Oh, perfect. :D
Thanks a lot pkSML.
_________________
My signature is so lame.

I think phpBB forums hates my laptop '.';
Back to top View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> PHP All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group