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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:35:01+00:00 2026-05-17T00:35:01+00:00

I have a file I use called fileCabinet.php to load in all my classes

  • 0

I have a file I use called fileCabinet.php to load in all my classes etc. It works great when my site is loaded from index.php via:

require_once('../includes/fileCabinet.php');

My issue is when I make Ajax calls, I want to use the same classes and would love to use the same file to load them, but the location of the ajax handling script is different from the location of the index.php so I end up with something that looks like this:

if($admin){
    $path = '../';
}else if($ajax){
    $path = '../../';
}

@require_once($path . 'admin/includes/generalFunctions.php');
@require_once($path . 'admin/corModules/PageAdmin.php');
@require_once($path . 'admin/corModules/SEOManager.php');

I have two different paths depending on where I’m calling from (admin or ajax). I’m wondering if there is a die-hard approach to locating your files no matter where the call for it comes from.

Thoughts?

  • 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-17T00:35:02+00:00Added an answer on May 17, 2026 at 12:35 am

    Inside fileCabinate.php include relative to that file only:

    require_once(__DIR__.'admin/includes/generalFunctions.php');
    require_once(__DIR__.'admin/corModules/PageAdmin.php');
    require_once(__DIR__.'admin/corModules/SEOManager.php');
    

    The __DIR__ magic constant is the directory of the current file, so in this case it’s assumed the three sub files are in the admin sub-folder.

    / 
    / fileCabinate.php
    / admin / includes /
                       / generalFunctions.php
    / admin / corModules /
                         / PageAdmin.php
                         / SEOManager.php
    

    Per op’s point – prior to 5.3, you needed to use:

    require_once(dirname(__FILE__).'admin/includes/generalFunctions.php');
    

    … oh how quickly we forget how it worked in the good ol’ days!

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

Sidebar

Related Questions

I'm trying to read a value from a file and use it in a
I have a file called tester.py , located on /project . /project has a
I have a file called config.yml in my /config folder of my rails application.
How do I self-instantiate a Java class? I should not use any file other
Scenario I have a windows service written in C# that performs some processing based
I have tried many ways of executing this but its not happening .. here
In Windows 7(i.e. MSI 5.0), there is a property called MSIFASTINSTALL which will improve
I am writing a JavaScript program in Rhino which needs to load other JavaScript
I'm currently trying to switch from Coda (a Mac IDE) to Vim. One thing
I'm writing a Python open-source app. My app uses some open source Python libraries.

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.