We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Proper way to get web_root

Development and Programming

lumis's avatar
lumis
119 posts
16 years ago
lumis's avatar lumis

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

       
lumis's avatar
lumis
119 posts
16 years ago
lumis's avatar lumis

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

       
Derek Jones's avatar
Derek Jones
7,561 posts
16 years ago
Derek Jones's avatar Derek Jones

Any reason you’re needing the web root instead of the folder that ExpressionEngine is being executed from?

       
lumis's avatar
lumis
119 posts
16 years ago
lumis's avatar lumis

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.

       
Derek Jones's avatar
Derek Jones
7,561 posts
16 years ago
Derek Jones's avatar Derek Jones

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.

       
mhulse's avatar
mhulse
329 posts
16 years ago
mhulse's avatar mhulse

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

       
mhulse's avatar
mhulse
329 posts
16 years ago
mhulse's avatar mhulse

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

       
Derek Jones's avatar
Derek Jones
7,561 posts
16 years ago
Derek Jones's avatar Derek Jones

RIght, that still has no correlation to web root. If it’s an uploaded file, you will want to use the path from the database for that upload location.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.