Page 1 of 1

php require and include paths

Posted: Wed Jul 08, 2009 9:37 am
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.

Re: php require and include paths

Posted: Thu Jul 09, 2009 3:28 pm
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 :)

Re: php require and include paths

Posted: Fri Jul 10, 2009 8:30 am
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.