title: PHP file path error for autoloader
body: <p>Here is my file structure on my cpanel webserver</p>
  
  <pre><code>root
     &gt; vendor
           &gt; autoload.php
     &gt; public_html
           &gt; folder
                 &gt; file2.php
           &gt; script_folder
                 &gt; include_file.php
           &gt; file1.php
  </code></pre>
  
  <p>Inside include_file.php I have</p>
  
  <pre><code> require_once('../vendor/autoload.php');
  </code></pre>
  
  <p>file1.php and file2.php both contain the same call to include_file.php</p>
  
  <pre><code> require_once($_SERVER["DOCUMENT_ROOT"]."/script_folder/include_file.php");
  </code></pre>
  
  <p>This works fine when I run file1.php but when I run file2.php i receive the following error message.</p>
  
  <blockquote>
    <p>No such file or directory Fatal error: require_once(): Failed opening required '../vendor/autoload.php' (include_path='.:/opt/cpanel/ea-php71/root/usr/share/pear') in /lvl1/lvl2/public_html/script_folder/include_file.php</p>
  </blockquote>
  
  <p>However, if I change <code>require_once('../vendor/autoload.php');</code> to <code>require_once('../../vendor/autoload.php');</code> in include_file.php then file2.php works and file1.php does not work.  It showes a similar error.</p>
  
  <p>I understand this is a file path issue but, what I don't understand is why.  Shouldn't the path in <code>include_file.php</code> always be the same no matter what file is calling it; i.e. file1.php or file2.php?  </p>
  
  <p>The way I see it is the the actual require_once statement is being called from include_file.php but, the behavior I'm seeing makes me think the require_once statement is being ran from file1.php or file2.php resulting in the filepath error.  </p>
  
  <p>Can someone please clarify?</p>
  
  <hr>
  
  <p>UPDATE:   inside include_file.php I have tried using:</p>
  
  <p><code>require_once($_SERVER["DOCUMENT_ROOT"] . '/vendor/autoload.php');</code></p>
  
  <p>and </p>
  
  <p><code>require_once(dirname(__FILE__).'/vendor/autoload.php');</code></p>
  
  <p>neither of these work since both return <code>public_html</code> as the main working directory.  My <code>vendor</code> folder is outside the main working directory.</p>
  
  <p>what is returned is this:</p>
  
  <p><code>/script_folder/vendor/autoload.php</code>  </p>
  
  <p>I understand I can simply include the correct file path at the beginning of <code>file1.php</code> and <code>file2.php</code> but, I was trying to figure out a way to reduce the number of requires I need in each file to only one by pointing them to <code>include_file.php</code>, then letting <code>include_file.php</code> do the rest of the work.</p>
  
  <p>My <code>include_file.php</code> file contains several other require statements to other scripts on my server.  Kind of like a mini autoloader.  All of the other require statements work fine except the <code>autoload.php</code> one I'm having trouble with here.  </p>
  
  <p>The only difference I can see is my other scripts are within my <code>public_html</code> folder and my <code>autoload.php</code> file is located outside of <code>public_html</code>.  </p>