Page 1 of 1
Path to an included file
Posted: Thu Jun 23, 2011 9:11 pm
by rednival
I am including a file that is on the include_path, but I would like to get full, physical path of the file. For instance, directory '/share/includes' is on my include_path and has the file foo.php in it. I include it using:
I want a way to convert 'foo.php' to '/share/includes/foo.php' so I know where the file came from.
Thoughts?
Re: Path to an included file
Posted: Thu Jun 23, 2011 11:31 pm
by twinedev
Try the following:
Code: Select all
$strFile = 'PEAR.php';
foreach (explode(':',get_include_path()) as $strCurPath) {
$strFullPath = realpath($strCurPath).'/'.$strFile;
if (file_exists($strFullPath)) {
echo "FOUND FILE AT: ",$strFullPath;
break;
}
$strFullPath = FALSE;
}
if (!$strFullPath) {
echo "ERROR: Count not find file in the path";
}
It will report the first found location, in the order that the includes (as far as I know) looks for it. In this sample, my server, PEAR.php is found in both
/usr/lib/php and
/usr/local/lib/php, but reported it in the first one found.
-Greg
Re: Path to an included file
Posted: Fri Jun 24, 2011 5:55 am
by rednival
EXACTLY what I needed. Thanks.
twinedev wrote:Try the following:
Code: Select all
$strFile = 'PEAR.php';
foreach (explode(':',get_include_path()) as $strCurPath) {
$strFullPath = realpath($strCurPath).'/'.$strFile;
if (file_exists($strFullPath)) {
echo "FOUND FILE AT: ",$strFullPath;
break;
}
$strFullPath = FALSE;
}
if (!$strFullPath) {
echo "ERROR: Count not find file in the path";
}
It will report the first found location, in the order that the includes (as far as I know) looks for it. In this sample, my server, PEAR.php is found in both
/usr/lib/php and
/usr/local/lib/php, but reported it in the first one found.
-Greg