PHP – Changing from Relative to Absolute Paths

I recently moved a bunch of PHP files into a new directory, and thus had to change the paths for my require_once() functions. The issue with relative paths is that if File A loads a File B, and File B resides in a different directory, File B tries to look for required files relative to File A.

The solution is to use absolute paths. Yagudaev has an excellent article showing a couple of different solutions for getting the absolute path you want. Here’s an example of what I did:

require_once ('../queries.php');
require_once (dirname(__FILE__) . '/../queries.php');
This entry was posted in PHP. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s