Page 1 of 1

Problems with scanning a dir.

Posted: Sun Oct 12, 2003 10:19 am
by Jim
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?

Posted: Sun Oct 12, 2003 10:50 am
by Stoker
missing absolute (or wrong relative) path?
perhaps try

is_dir($this->upload_folder . '/' . $files)

Posted: Sun Oct 12, 2003 10:54 am
by Jim
No good :( Same result.

Posted: Sun Oct 12, 2003 10:59 am
by Jim
As a further note, the variable $this->upload_folder is defined in the constructor of my File class. It's not an empty value.

Posted: Sun Oct 12, 2003 11:00 am
by Stoker
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.

Posted: Sun Oct 12, 2003 11:24 am
by Jim
The path is : "/home/files/public_html/files". I replaced the variable with that this time around and got the same result :(