find file
Posted: Wed Jan 09, 2008 3:56 am
You can use following code to find full path of the file you wanted
Code: Select all
<?
$main="test";
define('ROOT_PATH',str_replace('//','/',ereg_replace("((.*)/?)", "\\2", $_SERVER['DOCUMENT_ROOT']).(trim($main)!=''?"/".$main:'')));
function traverse($root,$destination)
{
$handle = opendir($root);
while (false !==($file=readdir($handle)))
if($file != '.' && $file != '..')
{
$full_path=$root."/".$destination;
if(file_exists($full_path))
return $full_path;
$path=$root."/".$file;
if(is_dir($path))
if($full_path=traverse($path,$destination))
return $full_path;
}
}
function absolutePathServer($destination)
{
if($full_path=traverse(ROOT_PATH,$destination))
return $full_path;
else
return $destination;
}
function absolutePathClient($destination)
{
if($full_path=traverse(ROOT_PATH,$destination))
return "http://".str_replace('//','/',str_replace($_SERVER['DOCUMENT_ROOT'],$_SERVER['HTTP_HOST']."/", $full_path));
else
return $destination;
}
?>