Re: setting the document root path in linux
| From: | Chris | Date: | Wed, 19 Sep 2007 07:24:21 +0000 |
| Subject: | Re: setting the document root path in linux | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-262228@lists.php.net to get a copy of this message | ||
tbt wrote:
Hi I'm a newbie to php and I'm using require_once($_SERVER['DOCUMENT_ROOT']."/includes/class.announcement.php"); to import pages in php. This works fine on a windows environment. However when I move this application to a linux environment the files dont get imported properly. This is because in a windows environment $_SERVER['DOCUMENT_ROOT'] returns c:/xampp/htdocs etc. but in a linux environment returns /home/servers etc. How can this be rectified so that the path is properly picked up in a linux environmentDon't rely on document root. I'm surprised it worked on windows, you were lucky - 90% of the time it's not there or not correct anyway. If it's in the same directory as the current file, do: require(dirname(__FILE__) . '/includes/class.announcement.php'); __FILE__ is a built in constant that tells you the full path to the current file. dirname() takes the filename out of that and gives you just the current directory (see http://www.php.net/dirname ). Then add the rest of the on the end. -- Postgresql & php tutorials http://www.designmagick.com/