Jump to content

Unable to list directory contents


Recommended Posts

I am trying to list the contents of different directories and I am having zero success. I have tested my PHP installation with phpinfo and through the PHP manager in IIS and it works. I am using IIS 7.5 and Win 2008 R2. I've made some basic scripts like what IP address does the machine have and they work. But, when I run the directory listing script in the root of the server it doesn't display any information. When I place the script in another directory it wants to download the file.

 

Here is the script I am using to display the directory contents. It came from another user on the phpfreaks.

 

$f = 0;

$d = 0;

// Open $var['path'] directory

if ($handle = opendir($var['path'])) {

    while (false !== ($file = readdir($handle))) {

        if ($file != "." && $file != ".." && is_dir("$var[path]/$file")) {

// $file is a directory

$dirList[$d] = $file;

$d++;

        }

elseif ($file != "." && $file != "..") {

// $file is not a directory           

$fileList[$f] = $file;

$f++;

}

    }   

closedir($handle);

}

@sort($fileList);

@sort($dirList);

for ($x = 0; $x < $d; $x++) {

$html .= "<a href=\"{$var['url']}/fileDir.php?dir=$dirList[$x]\">$dirList[$x]/</a><br>\n";

}

for ($x = 0; $x < $f; $x++)

{

$html .= "<a href=\"{$var['url']}/fileEdit.php?file=$fileList[$x]\">$fileList[$x]</a><br>\n";}

 

 

I have checked "I think" all the different settings I could and I cannot figure out why it won't display the directory contents. Could it be a rights issue? Right now I am IUSR to access the site, but I will be using windows authentication. Any information would be helpful. Thank you.

Link to comment
https://forums.phpfreaks.com/topic/222408-unable-to-list-directory-contents/
Share on other sites

I upgraded to PHP Version 5.3.4 today and I did a manual install. Everything worked until I renamed the php.ini-production to php.ini. I've followed the the recommended adjustments to the file, but after I did I started receiving - 500 - Internal server error message. I have several different manuals I've been using for configuring the ini file and I'm not sure what is right. Does anyone have a list of recommended changes to the ini file? Is there a setting in there that will allow directory listing - what I'm trying to figure out? I can run scripts like the one below fun.

 

<?php
$ip=@$REMOTE_ADDR; 
$ip=$_SERVER['REMOTE_ADDR'];

echo "<b>IP Address= $ip</b>"; 

?>

You have two different question now. One (listing directory contents) has nothing to do with PHP installation & configuration. It is likely either a permissions issue, or just bad code. Make sure the IUSR account has read access to the directories in question.

 

The other (your now misconfigured PHP install). Is php installed under fastcgi or as an module?

  • 2 weeks later...

Archived

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

×
×
  • 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.