I am a serious low-level PHP user, I get the basics up to a point, and I am using includes on my website. I am almost sure that what I asking is possible, but have no clue how to do it.
I have a nested folder in my website for my e-store, so my php include files inside the store are set to use ../inc/filename
but the local refs in those files are not being found, because they each have to be leveled up, also. This means I would have to create a separate includes directory just for the store and any changes to the main includes would also need to done in the store includes as well, creating double the work. I would prefer to pass on that option and find away to use a single include directory for everything on my website.
Also, since it is a photo site, I have hundreds of images already in directories. I would very much like to not have to use '../' for each image, it jumbles up the code, I prefer clean code.
I am trying to find a way to use PHP to DEFINE or SET or search or whatever to get them to automatically find the correct directories and not have to worry about leveling up everything. This way, the include files would be found and all the local href links will still work and all 'img' tag will find their correct directories without using '../img/filename' etc.
I am aware that live, I can just use /inc/filename
or /img/filename
, but locally on MAMP I get errors & it does not make for a good localhost development setup.
If there is an alternate way, I am open to all suggestions for clean & efficient way to make this happen. If you don't mind, please provide examples of how it works, I am very much a visible learning person.
Test site: Photo Store. I am constantly updating this so it maybe in a different state by the time you get to it, being very early in development and all, although the main site is complete.
Sample of my PHP page headers, this is from my main shop page the store directory. Notice I already created a separate include directory inside the store directory, but would prefer to just reference the main include directory one level up, provided examples of both.
`<?php
require('../../photoconfig.php');
ob_start();
$page_name = "Shop";
$page_id = "shop";
//using main include directory with level up as one option
include_once '../inc/top.php'; //doctype to head close
include_once '../inc/header-nav.php'; //body thru nav close
//using store include directory as second option
include_once 'str_inc/top.php'; //doctype to head close
include_once 'str_inc/header-nav.php'; //body thru nav close
error_reporting(E_ALL); // error reporting only used in development
?>`
Thank you so very much and have a great day!
Lisa Rose