Jump to content

directory listing problem


sheepz

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]
Link to comment
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! =)
Link to comment
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 :)
Link to comment
Share on other sites

  • 1 month later...
[!--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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.