Linux Format forums Forum Index Linux Format forums
Help, discussion, magazine feedback and more
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to list the contents of a folder on a web server?

 
Post new topic   Reply to topic    Linux Format forums Forum Index -> Other OS
View previous topic :: View next topic  
Author Message
nitromaster



Joined: Wed Feb 21, 2007 6:28 pm
Posts: 32

PostPosted: Mon Jun 11, 2007 8:42 pm    Post subject: How to list the contents of a folder on a web server? Reply with quote

title says it all,


is this possible?
Back to top
View user's profile Send private message
M0PHP
LXF regular


Joined: Wed Apr 06, 2005 8:40 am
Posts: 737
Location: Bishop Auckland, County Durham, UK

PostPosted: Mon Jun 11, 2007 9:02 pm    Post subject: RE: How to list the contents of a folder on a web server? Reply with quote

If you have access to the server then it is fairly easy - just enable directory listings Smile

To expand on that - if it's Apache and you do have access to the server config - just put this line in the directory configuration of the Apache config:

Code:
Options Indexes


Or you could also add that very same line to a .htaccess file (in the directory you want listings of) if you don't have access to the server but are still allowed htaccess.
_________________
Back to top
View user's profile Send private message Visit poster's website
JS
LXF regular


Joined: Thu Sep 13, 2007 12:27 am
Posts: 116

PostPosted: Wed Oct 10, 2007 5:25 pm    Post subject: RE: How to list the contents of a folder on a web server? Reply with quote

Alternatively, if you can't do htaccess but have PHP, then the following would work as a simple, minimal index.php:

Code:
<html>
<head>
<title> PHP index lister </title>
</head>
<body>
<h1> Directory listing </h1>
<?

# Change the . below to another directory name
# if you want to list the contents of a different directory
$handle = opendir('.');

if ($handle) {
   while (false !== ($file = readdir($handle))) {
      # The if clause below is only necessary
      # if you don't want to list this file and hidden files
      # (Leaving it is a good idea)
      if (($file[0] != ".") and ($file != "index.php"))
      {
         print "<a href=\"$file\">$file</a><br />\n";
      }
   }
}
closedir($handle);
?>
</body>
</html>

I've used it (well, a slightly modified version) myself, and it works for me.
Back to top
View user's profile Send private message
View previous topic :: View next topic  
Display posts from previous:   
Post new topic   Reply to topic    Linux Format forums Forum Index -> Other OS All times are GMT
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
Linux Format forums topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group


Copyright 2011 Future Publishing, all rights reserved.


Web hosting by UKFast