php require and include paths

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rsvirani
Forum Newbie
Posts: 2
Joined: Wed Jul 08, 2009 9:33 am

php require and include paths

Post by rsvirani »

I have a large web application with may include and require calls that look like '/home/file/...'. However, I cannot house the include files on my system's /home directory, nor can i create a sym link /home because there is an already existing and used directory there.

How can I redirect '/home' includes to another directory or force php to look for 'home' inside any include directories specified in php.ini? I cannot change all instances of /home' referenced in the web application.
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: php require and include paths

Post by Darhazer »

You have to change them. And never write paths in this way...
I always use:

Code: Select all

require_once( dirname(__FILE__) . '/path/to/file.php'
In this way, I'm always referring to path, relatively to the file I'm in, and I'm not relying on the current working directory and the full path is not hard-coded :)
rsvirani
Forum Newbie
Posts: 2
Joined: Wed Jul 08, 2009 9:33 am

Re: php require and include paths

Post by rsvirani »

I know, I never code absolute paths, but inherited this app and must maintain it. Anyway, it turns out the /home sym link in my way was created by auto_mount (mac) and has no function. I commented out the line and restarted and now the sym link is gone and I can place files there.
Post Reply