title: How do I include a PHP script from a base path other than the current script?
body: <p>I have a PHP application I'm trying to include, but it's causing problems because I'm trying to include its files from a subdirectory. For instance, here's the directory structure (more or less) I'm trying to work with:</p>
  
  <pre><code>/site
      /scripts
          /local
              some_script.php
      lib_file_a.php
      lib_file_b.php
      lib_load.php
  </code></pre>
  
  <p><code>lib_load.php</code> has an <code>include</code> command for files <code>lib_file_a.php</code> and <code>lib_file_b.php</code> (relative path).</p>
  
  <p>What I want to accomplish is to include <code>lib_load.php</code> from <code>some_script.php</code>, but there's a problem with the way I'm including <code>lib_load.php</code>. At first I tried <code>require('../../../lib_load.php');</code>.</p>
  
  <p>As you would expect I saw the error, "Failed opening required 'C:\xampp\htdocs\site\scripts\local\lib_file_a.php'". As you can see, PHP is trying to include a file that does not exist. I found a Stack Overflow post that told me about using an absolute path <a href="https://stackoverflow.com/questions/7378814/are-php-include-paths-relative-to-the-file-or-the-calling-code">(link)</a>, but this did not help. I next tried this code:</p>
  
  <pre><code>require(realpath(dirname(__FILE__) . '../../../' . 'lib_load.php'));
  </code></pre>
  
  <p>However, this time, the same error comes back. What am I doing wrong?</p>
  
  <p>EDIT: I realized that the issue was actually in the library loader, which turned out to be including files based on an absolute path, not a relative path. (I should have read more carefully.) I resolved the issue by changing the path used by the library. This question should be closed if a mod sees this request.</p>