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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:04:42+00:00 2026-05-15T08:04:42+00:00

I have a library of classes, all interrelated. Some files are inside the document

  • 0

I have a library of classes, all interrelated.

Some files are inside the document root and some are outside using the <Directory> and Alias features in httpd.conf

Assuming I have 3 files:

webroot.php (Inside the document root)
alias_directory.php (Inside a folder outside the doc root)
alias_directory2.php (Inside a **different** folder outside the doc root)

If alias_directory2.php needs both webroot.php and alias_directory.php, This does not work.
(Remember alias_directory.php and alias_directory2.php are not in the same locations)

require_once $_SERVER['DOCUMENT_ROOT'].'/webroot.php'; //(ok)
require_once $_SERVER['DOCUMENT_ROOT'].'/alias_directory.php'; //(not ok)

This does not work because alias_directory.php is not in the doc root.

Similarly

require_once $_SERVER['DOCUMENT_ROOT'].'/webroot.php'; //(ok)
require_once dirname(__FILE__).'/alias_directory.php'; //(not ok)

The problem here is that dirname(__FILE__) will return the path for alias_directory2.php not alias_directory.php.

This works:

require_once $_SERVER['DOCUMENT_ROOT'].'/webroot.php'; //(ok)
require_once '/full/path/to/directory/alias_directory.php'; //(ok)

But is very nasty and is a maintenance nightmare if I decide to move my library to another location.

How do I solve this problem, is seems that I need a way to resolve an Alias folder properly.

  • 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-15T08:04:42+00:00Added an answer on May 15, 2026 at 8:04 am

    PHP will not be able to resolve the location of your alias_directory.php file. You will need to supply the location of the alias_directory.php file yourself. Either as an absolute path, or relative to alias_directory2.php or the DOCUMENT_ROOT

    Example:

    If your file locations look something like this:
    /var/www/webroot.php
    /var/otherdir1/alias_directory.php
    /var/otherdir2/alias_directory2.php
    
    From alias_directory2.php you can now include alias_directory.php by either:
    require_once('/var/otherdir1/alias_directory.php');
    or
    require_once(dirname(__FILE__).'/../otherdir1/alias_directory.php');
    or
    require_once($_SERVER['DOCUMENT_ROOT'].'/../otherdir1/alias_directory.php');
    

    To use relative paths, alias_directory.php should be located somewhere close to alias_directory2.php or DOCUMENT_ROOT

    Another solution would be to add the folders in question to the include_path, and use require_once(‘alias_directory.php’); without path specification.

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

Sidebar

Related Questions

I have refactored some UIView sub-classes into a static library. However, when using Interface
Greetings all. I am writing some code using the Boost Units library and have
I have a data access library that has a few classes that all implement
I have a OCaml library with lots of classes I need some translator to
I have some C# library classes that make use of static variables. I use
I have a project that includes a shared library as source files. Some of
I'm compiling a Shared library using Android NDK r6b. All classes are C++. I
Many library classes in AS3 have read only properties. Is it possible to create
I have a C++ library that provides various classes for managing data. I have
I have a class library. In one of the classes, I am adding a

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.