if can only be used as separate statement, and can not occur within another statement such as include.
That being said you could use the ternary operator here:
If I understand correctly, in this case the ternary operator is saying if $filepath exist output $filepath. If not output nothing because the second argument is an empty string?
I have another somewhat related problem. I have these variables listed at the top of the document like so…
I would like to put these variables into an include so I can update them in a single place when I transfer the files to a live server. The catch 22 of course is that I can’t use these variables to call the include which contains these variables. How might I solve this problem?
Yes, you can generalize a lot of things when it comes to paths, but you have to make an assumption in bootstrapping; the index needs to know where it can find the config file.
I use dirname(FILE) to refer to the config file in the index. The config file is 1 dir up in my setup.
(not actual directory names of course, you get the idea)
so in index.php I use:
include(dirname(__FILE__).'/../config.php');
Now all that is assumed is the relation between the index and the config (namely, the config is one dir up from the index) without exactly specifying where it is (no physical path).
I’m trying to understand what you have written, but I’m not certain. I think you are suggesting that dirname(FILE) would be a better way to define the file path than creating a variable. Still, the dirname(FILE) resides in the index file?
Or are you saying use dirname(FILE) to call the config file only and use the variables for file paths in the document?
Or am I missing it altogether?
And the config file lives in the root folder? Is it necessary to place the config file in the root folder or can it go anywhere?
I always put the config file in a location that cannot be server by the web server. If possible that is. If it’s not possible I put it in a directory I deny all access to with a .htaccess deny from all