PDA

View Full Version : How To Show Contents Of Directory?



Guest_Dan_*
03-23-2005, 10:14 PM
Basically I want to create a subdomain so that I have access to a few of my music files while I'm away from home. I want to just be able to type in the web address (www.music.mydomain.com) and have it show a hyperlinked list of the files in that subdomain's directory (would be awesome if i could even put a password on it or something). Is there something special I need to do to make this happen?

ryan
03-23-2005, 10:26 PM
Originally posted by Guest_Dan_*@Mar 23 2005, 09:14 PM
Basically I want to create a subdomain so that I have access to a few of my music files while I'm away from home. I want to just be able to type in the web address (www.music.mydomain.com) and have it show a hyperlinked list of the files in that subdomain's directory (would be awesome if i could even put a password on it or something). Is there something special I need to do to make this happen?

Quoted post


Create your new subdomain by logging into Direct Admin and then clicking Subdomain Managment.

When you have finished that, navigate into the newly created folder for that subdomain usinf File Manager. Direct Admin will create this folder for you. Then create a new file called .htaccess notice the period before htaccess.

In this file type

Options +Indexes

Then you can browse to your subdomain and it will list the directory's contents.

Guest_Dan_*
03-23-2005, 10:29 PM
Originally posted by ryan+Mar 23 2005, 09:26 PM--><div class='quotetop'>QUOTE(ryan @ Mar 23 2005, 09:26 PM)</div><div class='quotemain'><!--QuoteBegin-Guest_Dan_*@Mar 23 2005, 09:14 PM
Basically I want to create a subdomain so that I have access to a few of my music files while I'm away from home.* I want to just be able to type in the web address (www.music.mydomain.com) and have it show a hyperlinked list of the files in that subdomain's directory (would be awesome if i could even put a password on it or something).* Is there something special I need to do to make this happen?

Quoted post


Create your new subdomain by logging into Direct Admin and then clicking Subdomain Managment.

When you have finished that, navigate into the newly created folder for that subdomain usinf File Manager. Direct Admin will create this folder for you. Then create a new file called .htaccess notice the period before htaccess.

In this file type

Options +Indexes

Then you can browse to your subdomain and it will list the directory's contents.

Thanks for choosing HostPC
Ryan
HostPC Support Team

Quoted post
[/b][/quote]

Awesome! Is there a way to password protect it? Just to keep any leechers out? Doesn't have to be bulletproof, just something simple...

ryan
03-23-2005, 10:51 PM
Actually there is a better way... delete the .htaccess file and create a file called index.php with this:


<html>
<head>
<title>Directory List</title>
</head>
<body>
<h2>Directory Listing</h2>
<?php
$path_to_folder="./";
$dir=opendir($path_to_folder);
echo "<ul>\n";
while($file=readdir($dir))
{
if($file != "." && $file != ".." && $file!="index.php")
{
echo"<li><a href=\"".$file."\" target=\"_blank\">".$file."</a></li>\n";
}
}
echo "</ul>\n";
closedir($dir);
?>
</body>
</html>

Basically does the same thing just it's more secure...
There is an option in the Direct Admin control panel called "Password Protect Directories. That will do what you want...

Awesome! Is there a way to password protect it? Just to keep any leechers out? Doesn't have to be bulletproof, just something simple...

Quoted post
[/quote]

Guest_Dan_*
03-23-2005, 11:10 PM
Nice! Thanks!

One last question and I promise I'll stop bugging you. :-)

How can I hide, or exclude certain files or directories from showing? For example, I can see "cgi-bin" and ".htaccess" listed. Is it possible to exclude, or filter these from the listing?

You are the man, I really appreciate the help! This is a HUGE help for me while I'm on the road! :-)

eugene
03-24-2005, 02:25 AM
At least two ways:
1. If you use the php file, add the exclusions to the

if($file != "." && $file != ".." && $file!="index.php")
statement.
2. Set the file permissions so that they will not show.