Searched the net but couldn't find anything. 🆒
Whats the difference between:
define(IMAGE_BASE, '/var/www/html/mbailey/images');
And
define(IMAGE_BASE, 'mbailey/images');
To define a path to a folder? I normally use the second.
You can use the first example in any dir and it will work, its only problem is that it is not portable.
The first one specifies an absolute path to the directory (I assume its a directory). So wherever you deploy the code that path must be readable or writable or whatever you need it to be in order to work.
The second specifies a directory relative to some other directory. Now heres the rub...it can get a little dicey to know relative to exactly "relavtive to what" you are talking about depending on where the file that contains that define() statement is included.
Here's what I do:
have a config.php file that contains all my configuration settings for the site, which is typically a bunch of define() statements
somewhere in config.php I have a define('ROOT', dirname(FILE)); This sets up a constant that contains the absolute path to my config file...typically I put config.php in the top level (ie document root) of the web site.
I define all my paths as ROOT . '/some/path/images' so they are absolute paths but exactly what the absolute path is depends on where my config file is located. Eg: define('TEMPLATE_DIR', ROOT . '/templates');
This is very portable and eliminates many head aches trying to track down errors with include() ... and typically I use require_once() and not include() so I get a big fat error if something goes wrong.
You could sort of get the best of both worlds (realtively portable and works from any directory) with:
define('SOME_PATH', $_SERVER['DOCUMENT_ROOT'].'/directory/file.php');
(This would be analogous to what JazzSnob posted while I was typing, but his will be even more portable if you can't be positive where your application code will be installed in relation to the web root directory..)