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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:03:04+00:00 2026-05-13T20:03:04+00:00

I have always used relative paths in PHP. Last time I have realized that

  • 0

I have always used relative paths in PHP. Last time I have realized that there were something like absolute paths.

But what is the best way to use them?

getenv("DOCUMENT_ROOT"); ?
dirname(__FILE__); ?

How do you deal with the implementation? Please give some ideas.

  • 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-05-13T20:03:04+00:00Added an answer on May 13, 2026 at 8:03 pm

    When I want to use files that are “relative” to the one in which I am writing some code, I’m always using :

    dirname(__FILE__)
    

    This allows me to :

    • have absolute paths that’ll work everywhere, no matter to which server I deploy my application
    • still use path that “look like” relative ones when I’m writting them.

    For instance, to include a file that’s in a “classes” sub-diretory, I would generally use :

    require dirname(__FILE__) . '/classes/MyClass.php';
    

    Note that this will work even if you’re executing your script from the command-line — while a solution based on some kind of DocumentRoot will probably not work when not using a web-server.

    And, with PHP >= 5.3, you can also use the __DIR__ magic constant, which has exactly the same value as dirname(__FILE__), but is evaluated at compile-time, and not execution-time — which is a bit better for performances.

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

Sidebar

Related Questions

I have always used Authlogic in Rails 2.3 but now that I am using
I have always used the mouseover event, but while reading the jQuery documentation I
We have always had languages that were preferable to be used in a particular
I have always used a Singleton class for a registry object in PHP. As
I have been using Unity for quite a while but I have always used
I have always used either a <br /> or a <div/> tag when something
I am using the same php code I have always used to try and
Possible Duplicate: PhpMailer vs. Swiftmailer? I have always used PHP's built in mail() function
I have always used the Visual Studio Dependencies option to ensure that, for example,
It's my first time using PostgreSQL 8.4.2 with Django(I have always used MySQL or

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.