mtd
06-04-2005, 08:15 PM
Hello! I am working on a small piece of code as part of a larger project, and I have run into a predicament of sorts:
I started with this code:// Write File Select Section:
$dir_name = ".";
$dh = opendir($dir_name) or die("Couldn't open specified directory.");
echo "<!-- File selections --> \n";
echo "<form action=\"testpage.php\" method=\"POST\"><select name=\"search_this_file\">";
while (!(($file = readdir($dh)) === false ) ) {
if (($file != ".") && ($file != "..")) {
echo "<option value=\"".$file."\"";
global $search_this_file;
if ($file == $search_this_file) {
echo " selected";
}
echo ">".$file."</option>";
}
}
echo "</select><input type=\"submit\" value=\"Go\"></form> \n";
closedir($dh);Basically, it reads the contents of the current directory, excludes the "." and ".." written for parent directories, and writes the remaining contents to a select box.
The problem is, the rest of my code depends on $search_this_file being an actual file, not a folder (if the form is submitted and $search_this_file is a folder, an error occurs). What I need is code that will determine whether each of the contents of the directory is either a file or a folder. Is there an easy way to do this?
I started with this code:// Write File Select Section:
$dir_name = ".";
$dh = opendir($dir_name) or die("Couldn't open specified directory.");
echo "<!-- File selections --> \n";
echo "<form action=\"testpage.php\" method=\"POST\"><select name=\"search_this_file\">";
while (!(($file = readdir($dh)) === false ) ) {
if (($file != ".") && ($file != "..")) {
echo "<option value=\"".$file."\"";
global $search_this_file;
if ($file == $search_this_file) {
echo " selected";
}
echo ">".$file."</option>";
}
}
echo "</select><input type=\"submit\" value=\"Go\"></form> \n";
closedir($dh);Basically, it reads the contents of the current directory, excludes the "." and ".." written for parent directories, and writes the remaining contents to a select box.
The problem is, the rest of my code depends on $search_this_file being an actual file, not a folder (if the form is submitted and $search_this_file is a folder, an error occurs). What I need is code that will determine whether each of the contents of the directory is either a file or a folder. Is there an easy way to do this?