I am building my first website in PHP. I am testing it locally and have two computers I am developing it on, my home computer and my Uni computer, with the main project stored in Dropbox.
The project has different root paths on both computers as they have different user names.
‘/home/vadar/Dropbox/ENELWebsite/public_html/’
‘/home/tcpb1/Dropbox/ENELWebsite/public_html/’
This obviously has become a problem as including files using the root path will result in an error on one computer.
I originally tried include this at my index pages, but it also requires a root path for the include file containing it, which I would have to change between computers.
$dir_home = '/home/vadar/Dropbox/ENELWebsite/public_html/';
$dir_uni = '/home/tcpb1/Dropbox/ENELWebsite/public_html/';
if(file_exists($dir_home) OR is_dir($dir_home)){
define('APP_DIR', $dir_home); //home comp
}
elseif(file_exists($dir_uni) OR is_dir($dir_uni)){
define('APP_DIR', $dir_uni); //uni comp
}
else{
echo 'No include directory exists';
}
What is the smartest way to solve this problem? I realise I could just make a new user folder on either one of them, and move the Dropbox folder into it, but I am sure there is a smarter way to include files in the project itself.
Use $_SERVER[‘DOCUMENT_ROOT’] to find the root folder.