Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8060753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:05:43+00:00 2026-06-05T10:05:43+00:00

I rely heavily in $_SERVER[DOCUMENT_ROOT] to get absolute paths. However this doesn’t work for

  • 0

I rely heavily in $_SERVER["DOCUMENT_ROOT"] to get absolute paths. However this doesn’t work for sites which URLs don’t point to the root.

I have sites stored in folders such as:

  • site1
  • site2

all directly inside the root. Is there a way to get the path in the server where the current site root is?

It should return:

   /var/chroot/home/content/02/6945202/html/site1 // If the site is stored in folder 'site1'
   /var/chroot/home/content/02/6945202/html // If the site is stored in the root
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T10:05:45+00:00Added an answer on June 5, 2026 at 10:05 am

    You can simply append dirname($_SERVER['SCRIPT_NAME']) to $_SERVER['DOCUMENT_ROOT'].

    Update

    The website seems to be directory “mounted” on that folder, so SCRIPT_NAME will obviously be /.

    So, to make this work you have to use either __DIR__ or dirname(__FILE__) to find out where your script is located in the file system.

    Update 2

    There’s no single index.php controller for the whole site, so that won’t work either.

    The following expression does a string “subtraction” to find the common path. You have a known prefix (document root), an unknown (the root folder) and a known suffix (the script path), so to find the first two, you take the full absolute path (__FILE__) and subtract the known suffix:

    substr(__FILE__, 0, -strlen($_SERVER['SCRIPT_NAME']));
    

    If included files need this value, you must store this in a constant first before including the dependent scripts. .

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I rely on ImageCR3 for a number of my sites. However, I've come up
I'm writing an app which will rely heavily on the use of a database.
I rely heavily on nested Master Pages in my web portal, this causes ASP.NET
Facebook is heavily JavaScript based. Why doesn't it rely on jQuery (or any other
(This question does not rely on a specific IoC framework, so the interfaces and
Most of the units I work on rely on a Data Module. One of
On CPUs like x86, which provide cache coherency, how is this useful from a
I am planning the development of a website that rely heavily on facebook integration,
I have a set of vb.net classes and functions that heavily rely on the
I'm trying to rely more heavily on git-svn for all my tasks, rather than

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.