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!
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:
$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.
$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.