Readdir problem
Posted: Wed Oct 25, 2006 12:36 am
Iam having problems trying to read the contents of a directory. This is the code that I use:
I get the directory from a form in an html file using the GET method. I have tested this script using various directories in my server and even the simplest one (. current directory) does not work. You can test the code yourselves at:
http://www.eng.umd.edu/enme331/wpc.html
It seems that the directory is valid because the code goes through the opendir statement and prints the directory name. It also seems to go into the while loop once because there are two <BR> printed. However the $file variable obtained from the readdir is empty.
I have checked two things:
1. The local (.) directory itself contains about 8 files and in the directory all the files have read permissions (-rw-r--r--)
2. The server allows directory reading (allow_url_fopen is ON, http://www.eng.umd.edu/enme331/info.php)
Any idea why I cannot read the contents of a directory? What am I doing wrong?
Thank you,
Nikolaos
Code: Select all
<HTML>
<HEAD><TITLE>TEST</TITLE></HEAD>
<BODY>
<?php
$address = $_GET['wb'];
if($dire = opendir($address));
{
print("Directory name: $address<BR>\n");
while(false !== ($file=readdir($dire)) );
{
print("$file<BR>\n");
}
closedir($dire)
}
?>
</BODY>
</HTML>http://www.eng.umd.edu/enme331/wpc.html
It seems that the directory is valid because the code goes through the opendir statement and prints the directory name. It also seems to go into the while loop once because there are two <BR> printed. However the $file variable obtained from the readdir is empty.
I have checked two things:
1. The local (.) directory itself contains about 8 files and in the directory all the files have read permissions (-rw-r--r--)
2. The server allows directory reading (allow_url_fopen is ON, http://www.eng.umd.edu/enme331/info.php)
Any idea why I cannot read the contents of a directory? What am I doing wrong?
Thank you,
Nikolaos