PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Jim
Forum Contributor
Posts: 238 Joined: Fri Apr 19, 2002 5:26 am
Location: Near Austin, Texas
Post
by Jim » Sun Oct 12, 2003 10:19 am
Having trouble with this:
Code: Select all
function seek_files()
{
global $SQL;
global $conf;
global $error;
// Let's get to scanning the directory...
if ( is_dir($this->upload_folder) )
{
if ($handle = opendir($this->upload_folder))
{
while (($files = readdir($handle)) !== false)
{
if ($files != ".." && $files != ".")
{
if ( is_dir($files) )
{
$direc[] = $files;
}
else
{
$file[] = $files;
}
}
}
// Sort and print files and directories.
if ( is_array($direc) )
{
sort ($direc);
foreach ($direc as $dir)
{
echo "<b>" .$dir. "</b><BR>";
}
}
elseif ( is_array($file) )
{
sort ($file);
foreach($file as $fil)
{
echo "<i>" . $fil . "</i><BR>";
}
}
}
else
{
$error -> print_error("bad_read");
}
}
else
{
$error -> print_error("no_dir");
}
}
Generally speaking it works fine... but rather than separating files and directories, it prints all files and directories as if they were both files.
No distinction whatsoever...
Any idea what the problem might be?
Stoker
Forum Regular
Posts: 782 Joined: Thu Jan 23, 2003 9:45 pm
Location: SWNY
Contact:
Post
by Stoker » Sun Oct 12, 2003 10:50 am
missing absolute (or wrong relative) path?
perhaps try
is_dir($this->upload_folder . '/' . $files)
Jim
Forum Contributor
Posts: 238 Joined: Fri Apr 19, 2002 5:26 am
Location: Near Austin, Texas
Post
by Jim » Sun Oct 12, 2003 10:54 am
No good
Same result.
Jim
Forum Contributor
Posts: 238 Joined: Fri Apr 19, 2002 5:26 am
Location: Near Austin, Texas
Post
by Jim » Sun Oct 12, 2003 10:59 am
As a further note, the variable $this->upload_folder is defined in the constructor of my File class. It's not an empty value.
Stoker
Forum Regular
Posts: 782 Joined: Thu Jan 23, 2003 9:45 pm
Location: SWNY
Contact:
Post
by Stoker » Sun Oct 12, 2003 11:00 am
welll, if your list of files has the files/dirs in the correct location, it is obveious that the is_dir() fails, and the only way it can fail is if the dir/name tested is not accessible (permissions) or is nonexistent in the path you are searching, so concentrate your debugging there, do an echo of the same value you are doing is_dir on, I recommend making sure it is an absolute path.
Jim
Forum Contributor
Posts: 238 Joined: Fri Apr 19, 2002 5:26 am
Location: Near Austin, Texas
Post
by Jim » Sun Oct 12, 2003 11:24 am
The path is : "/home/files/public_html/files". I replaced the variable with that this time around and got the same result