Page 1 of 1

File Browsing With PHP?

Posted: Tue Jun 08, 2004 5:15 am
by mikeypengelly
I have 2 servers running red hat 9 and php called www2 and www3.
I am trying to run a file search script that will simply run hrough a directory and search for occurrances of a keyword.

The script works on www2 but not on www3. PHP works on both. both php.ini files are identical after chaning one value to on but it still doesnt seem to work.

I would imaging it would be a configuration issue rather than a code issue but i am open to any suggestions if anyone has any ideas.

Thanks in advance.

Posted: Wed Jun 09, 2004 5:02 am
by patrikG
You want PHP to do the job?

A nudge in the right direction would be:

Code: Select all

<?php
function get_directory_contents($path){
	$mydirectory = opendir($path);
	while($entryname=readdir($mydirectory)){
		switch (true){
			case ($entryname==".")               : break;
			case ($entryname=="..")              : break;
			case (is_dir($path."/".$entryname))  : $return["dir"][]=$entryname; break;
			default                              : $return["file"][]=$entryname;
		}
	}
	closedir($mydirectory);
	return $return;
}

echo "<h3>directory contents</h3><pre>";
print_r(get_directory_contents("./"));
echo"</pre>";
?>
That'll return subdirectories and files in a directory. If you filter the array it returns with a search-function, you should get what you need.