Jump to content

Archived

This topic is now archived and is closed to further replies.

sheepz

directory listing problem

Recommended Posts

i want to have a script that will work just like "directory browsing" i found this script on this site, i'm not sure where i found it, but it does work. the problem that i do have is when i change the $path = "/scripts/"; the folders with in that folder wont open. it gives me a "page cannot be found" but if i use $path = "./"; it works fine, the folders within that folder would open just like "directory browsing" the reason i need this to be /scripts/ is because i dont want the users to be able to access the wwwroot folder and it's contents. is there something wrong with the script that when i change the $path it wont open subfolders? if i use the "./" root folder it opens subfolders fine.


[code]
<html>
<head>
<title> Directory List</title>
</head>
<body>
<h2> Directory listing </h2>


<?
$path = "./";
$dir = opendir($path);
echo "<ul>\n";

while($file = readdir($dir))
    {
    if ($file != "." && $file != ".." && $file != ".php")
        {
        echo "<li><a href = \"" .$file. "\" target = \" _blank\"> ".$file." </a></li> \n";
        }
    }
echo "</ul>\n";
closedir($dir);
?>
</body>
</html>
[/code]

Share this post


Link to post
Share on other sites
try using scripts/ instead of /scripts/ because /scripts/ points to the root of the hdd then /scripts which im guessing your looking to search a directory within the foleder your already in which is called scripts?

Share this post


Link to post
Share on other sites
[!--quoteo(post=359961:date=Mar 30 2006, 01:40 AM:name=shocker-z)--][div class=\'quotetop\']QUOTE(shocker-z @ Mar 30 2006, 01:40 AM) [snapback]359961[/snapback][/div][div class=\'quotemain\'][!--quotec--]
try using scripts/ instead of /scripts/ because /scripts/ points to the root of the hdd then /scripts which im guessing your looking to search a directory within the foleder your already in which is called scripts?
[/quote]


the folder i want people to access is "c:\inetpub\wwwroot\scripts" when i put the folder path to "./" it will get me to the root directory of wwwRoot, and all the subfolders open correctly. When i put the folder path to "/wwwroot/scripts/" all the files work fine but the subfolder do not open correctly. i tried putting the path to "scripts/" but still no luck, when i click on the subfolders i get a "page cannot be displayed.

thanks for the reply! =)

Share this post


Link to post
Share on other sites
<html>
<head>
<title> Directory List</title>
</head>
<body>
<h2> Directory listing </h2>


<?
$path = "../mail/";
$dir = opendir($path);
echo "<ul>\n";

while($file = readdir($dir))
{
if ($file != "." && $file != ".." && $file != ".php")
{
echo "<li><a href = \"" .$path.$file. "\" target = \" _blank\"> ".$file." </a></li> \n";
}
}
echo "</ul>\n";
closedir($dir);
?>
</body>
</html>


Use that i added $path before the filename :) You could check to see if it's a dir and if so then change the link to ?path=$file and then it can search inside other folders instead of treating them as normal files :)

Share this post


Link to post
Share on other sites
[!--quoteo(post=360205:date=Mar 31 2006, 07:54 AM:name=sheepz)--][div class=\'quotetop\']QUOTE(sheepz @ Mar 31 2006, 07:54 AM) [snapback]360205[/snapback][/div][div class=\'quotemain\'][!--quotec--]
you are awsome, it works exactly the way i want it to! thx a bunch!
[/quote]

Is there a way to remove the file extension when it's displayed?

Maybe using [!--coloro:#3333FF--][span style=\"color:#3333FF\"][!--/coloro--]basename()[!--colorc--][/span][!--/colorc--]?

Thanks!

Joe

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.