I have struggled with a universal way to find the servers web_root including using $_server[‘DOCUMENT_ROOT’] or $_ENV[‘DOCUMENT_ROOT’] and other php server vars….
right now i am using
$base_path = $FNS->set_realpath("./");
$base_path = str_replace("\\", "/", $base_path);
i have thought about using $FNS->set_realpath(PATH); and stepping up one folder but that would not work to well for MSM sites.
$FNS->set_realpath(“./”) works grate for me on dreamhost and EngineHosting, but nothing i have found so far is working universally . I have a override param for setting the base_path in the tag but It would be nice if the base_path default would work 100% for everyone without the need to set it via a param.
any ideas or suggestions? perhaps there is something i am overlooking?
Thanks much
never mind this was just to problematic depending on peoples server configurations, so i just reverted back to the old way the plug-in was finding the base_path by default.
simple
if (array_key_exists('DOCUMENT_ROOT',$_ENV))
{
$base_path = $_ENV['DOCUMENT_ROOT'];
}
else
{
$base_path = $_SERVER['DOCUMENT_ROOT'];
}
This seems to work fine for servers only reporting this in ENV OR _SERVER If anyone knows a more universal way let me know
Hi Derek what i am doing is building the absolute path to a image on the server based on webroot and the relative path supplied by the user. ./ works for me but i found allot of people have strange setups so ‘DOCUMENT_ROOT’ concatenated with user supplied relitive path seems to work more universally.
I don’t guess I’m really following on how that correlates to finding the web root, as ExpressionEngine and the user’s files could be anywhere. I’d give a specific recommendation for how to get it if I had a larger overall picture of what you’re doing, i.e. where the relative path is coming from, what types of files are being referenced (EE uploaded files? Themes specific to your add-on?), and whether this executes from the control panel or the user side.
Hi Derek,
For me, getimagesize() function needs to be a base server path in order to work (at least on my server).
On the other hand, my work servers do not care if the path is from the root.
Essentially, I am in the same boat as Lumis.
I like the posted solution though… I prefer writing it like this:
$base_path = (array_key_exists('DOCUMENT_ROOT', $_ENV)) ? $_ENV['DOCUMENT_ROOT'] : $_SERVER['DOCUMENT_ROOT']; // Server root path.
Anyone know how bullet proof that is?
Thanks, M
Lumis,
I noticed that in your image sizer plugin, you use this code:
$base_path = str_replace("\\", "/", $base_path);
$base_path = $FNS->remove_double_slashes($base_path);
Just out of curiosity, what are you doing here? Should I be concerned with extraneous slashes when setting up the root/base path?
Thanks! M
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.