I have a directory tree like the below
root
index.php
/inc
1levelData.php
1level.php
/images
db.png
What I am trying to figure out is a way I can set an absolute path that can be used for both including files and images. In addition, a method that will work when loading both index.php
as well as root\inc\1level.php
I have put in some sample code below for what I am currently working with. This code seems to work well for include()
but doesn't function for images. Is there a possible fix?
root/Index:
<?php
$fullPath = realpath($_SERVER['DOCUMENT_ROOT']);
echo "<img src = '".$fullPath."/inc/images/db.png'><BR>";
include $fullPath.'/inc/1levelData.php';
?>
root/inc/1levelData.php
<?php
echo "<img src = '".$fullPath."/inc/images/db.png'><BR>";
include ($fullPath.'/inc/images/2levelData.php');
?>
root/inc/1Level.php
<?php
$fullPath = realpath($_SERVER['DOCUMENT_ROOT']);
include ($fullPath.'/phpinfo.php');
?>
root/inc/2LevelData.php
<?php
echo "<img src = '".$fullPath."inc/images/db.png'><BR>";
?>