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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:29:43+00:00 2026-05-26T19:29:43+00:00

This is the code I’m using (it’s the index.php file) /* Set an include

  • 0

This is the code I’m using (it’s the index.php file)

/* Set an include path
*/
$dir = explode('/', __DIR__);
$i = count($dir);
unset($dir[$i-1], $dir[$i-2]);
$path = implode('/', $dir);
ini_set('include_path', $path);

// require('system/base/file.php'); // ***1

/* Starter file
*/
if (file_exists('system/base/file.php')) { require('system/base/file.php'); }
else { exit('Error'); }

I’m developing a framework that has this structure

application/
    public/
        index.php
system/

And I want to set the include path to the root/ (the folder that contains application/ and system/). __DIR__ is giving me a lot of things suchs as Application/xammp/htdocs/application/public/index.php (in localhost); I’m not really sure that clients __DIR__ is so much different, considering that I don’t know nothing about the path in the first place. I just wrote those first few line to easily delete the last 2 folders from DIR so I’m sure that the path is right whatever __DIR__ is. I tested those lines in another test setting and they are working fine.

The strange thing that happens is that if I run the the code as it is shown up there it gives me “Error”. While if I just require system/base/file.php before checking it’s existence it works. So if I uncomment (***1) the file is required.

  • 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-26T19:29:44+00:00Added an answer on May 26, 2026 at 7:29 pm

    You could use $path = dirname(dirname(DIR)), this will achieve the same thing that your first 5 lines of codes do.

    According to the PHP documentation, include_path only works with: require(), include(), fopen(), file(), readfile() and file_get_contents(), not file_exists(). Therefore, you will have to store $path in a variable or a constant. For example:

    /* Set an include path
    */
    $path = dirname(dirname(__DIR__));
    ini_set('include_path', $path);
    define('PATH', $path)
    
    // require('system/base/file.php'); // ***1
    
    /* Starter file
    */
    if (file_exists(PATH . 'system/base/file.php')) { require('system/base/file.php'); }
    else { exit('Error'); }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This code fails when I try to debug it using VC2010: char frd[32]=word-list.txt; FILE
this code always returns 0 in PHP 5.2.5 for microseconds: <?php $dt = new
This code works; int at(int index) { if(index < 1 || index >= size)
This code is ment to download the source code of an html file but
This code works properly in my localhost. I am using xampp 1.7.3. but when
This code i put it in the HTML page for check the file value,
This code: <% string path = Request.ApplicationPath.ToString(); %> <link href=<%= path %>/Content/Site.css rel=stylesheet type=text/css
This code URL listofFiles = this.getClass().getResource(someDir); File f = new File(listofFiles.toString()); File[] files =
This code selects cell values in MySQL and manually adds them to PHP variables:
this code using an OLEDB source will populate the OutputColumnCollection below it, the code

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.