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 8970145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:41:27+00:00 2026-06-15T17:41:27+00:00

$thisFile = str_replace(‘\\’, ‘/’, __FILE__); $docRoot = $_SERVER[‘DOCUMENT_ROOT’]; $webRoot = str_replace(array($docRoot, ‘library/config.php’), ”, $thisFile);

  • 0
$thisFile = str_replace('\\', '/', __FILE__);
$docRoot = $_SERVER['DOCUMENT_ROOT'];

$webRoot  = str_replace(array($docRoot, 'library/config.php'), '', $thisFile);
$srvRoot  = str_replace('library/config.php', '', $thisFile);

This is how I get the web root and the server root

web root is the folder name where my files belongs, server root is the C:/xampp/htdocs/folder_name

I just want to ask when should I use webroot and server root.

I just notice that if you are referencing a file ex: href or img src, then only web root works but not server root

But, if you require a file, ex. require_once 'file.php'; only server root works not webroot

  • 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-15T17:41:28+00:00Added an answer on June 15, 2026 at 5:41 pm

    You are confusing the server path with the URL path.

    On your server, the files are stored at C:/xampp/htdocs/folder_name, but according to your web browser, they are at http://localhost/folder_name. When your browser loads the files, it doesn’t know they are in C:/xampp/htdocs/.

    NOTE: None of the code you have there will get you the “web root”.

    __FILE__ will return the path of the file on your server, like: `C:/xampp/htdocs/include/header.php.

    $_SERVER['DOCUMENT_ROOT'] will return you the path on the server where the files are, like: C:/xampp/htdocs/.

    To get your “web root”, you need to use $_SERVER['SERVER_NAME']. This will return you example.com (or whatever). You’re probably gonna need to append http(s):// to it.

    $serverRoot = $_SERVER['DOCUMENT_ROOT'];
    $webRoot = ($_SERVER['HTTPS'] ? 'https://' : 'http://') . $_SERVER['SERVER_NAME'];
    

    You can also just use / as your web root.

    <img src='http://example.com/images/wall.png" />
    

    and

    <img src='/images/wall.png" />
    

    should be equivalent.

    Try to var_dump($_SERVER);, it’ll give you some fun information.

    EDIT: Use dirname if you want to get the “sub folder” under the “root folder”. The above will give you the main root.

    $serverPath = dirname(__FILE__); // or __DIR__
    $webPath = dirname($_SERVER['PHP_SELF']);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to check in my SD card root for files starting with thisfile
I have this file 'gardens.php' , which pulls data from a table called 'generalinfo'
This is part of my navigation page but it sends me to mysite.com/mysite.com/myfolder.php <a
I've making a shared library (cross-platform), but when trying to compile the Windows build
I am using the sqlite3 library of python to process a Wikipedia .sql data
I have a php file for uploading a picture (it uploads the picture, creates
This code is copy from http://code.google.com/p/closure-library/source/browse/trunk/closure/bin/build/source.py The Source class's __str __method referred self._path Is
I have a php file that prints the last 50 lines of a txt
I'm trying to use PHP to create a shell script on Windows. It's part
Okay, I know nothing of Ruby, I am building a PHP website and decided

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.