Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I set an absolute include path in PHP?
    text
    copied!<p>In HTML, I can find a file starting from the <strong>web server's</strong> root folder by beginning the filepath with "/". Like:</p> <pre><code>/images/some_image.jpg </code></pre> <p>I can put that path in any file in any subdirectory, and it will point to the right image.</p> <p>With PHP, I tried something similar:</p> <pre><code>include("/includes/header.php"); </code></pre> <p>...but that doesn't work.</p> <p>I think that that <a href="http://us2.php.net/manual/en/ini.core.php#ini.include-path" rel="noreferrer">this page</a> is saying that I can set <code>include_path</code> once and after that, it will be assumed. But I don't quite get the syntax. Both examples start with a period, and it says:</p> <blockquote>Using a . in the include path allows for relative includes as it means the current directory.</blockquote> <p>Relative includes are exactly what I <strong>don't</strong> want.</p> <p><strong>How do I make sure that all my includes point to the <code>root/includes</code> folder?</strong> (Bonus: what if I want to place that folder outside the public directory?)</p> <h2>Clarification</h2> <p>My development files are currently being served by XAMPP/Apache. Does that affect the absolute path? (I'm not sure yet what the production server will be.)</p> <h2>Update</h2> <p>I don't know what my problem was here. The <code>include_path</code> thing I referenced above was exactly what I was looking for, and the syntax isn't really confusing. I just tried it and it works great.</p> <p>One thing that occurs to me is that some people may have thought that "/some/path" was an "absolute path" because they assumed the OS was Linux. This server is Windows, so an absolute path would have to start with the drive name.</p> <p>Anyway, problem solved! :)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload