anmdei34 Posted December 27, 2007 Share Posted December 27, 2007 I have include files located above the document in my website. On my Apachee localhost I set my document root directory structure beneath my server root to be the same as my live server. The problem is that I can't get the includes to work on my localhost and they work fine on the live server. So what I have resorted to do is to change the paths of all my include statments every time I upload my files to the live server. That is a huge pain. Doesanybody have any advice? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted December 27, 2007 Share Posted December 27, 2007 Check your web server log for errors that would help find out why it is not working on your local computer. For anyone in a forum to be able to help, you would need to post examples of what your path looks like. This could be a permissions problem (you need to provide information like what operating system you are using), it could simply be an incorrect path statement that you are trying, or it could be something like safe mode being on. If you cannot solve the problem, the solution is to create a defined constant that holds the base portion of the file system path that you use in the include() statements instead of editing things. Then simply have a configuration file that gets included that has the correct value in the defined constant, one on your local computer and one on your live site. Quote Link to comment Share on other sites More sharing options...
anmdei34 Posted December 27, 2007 Author Share Posted December 27, 2007 Thanks for the reply, My system is a Windows xp Apache Server 2.0.59 PHP Version 5.2.4 ServerRoot "C:/webserver/Apache2" DocumentRoot "C:/webserver/Apache2/home/bobharri/www" safe_mode = Off I checked my log file: [Thu Dec 27 16:19:30 2007] [error] [client 127.0.0.1] PHP Warning: include(\\home\\bobharri\\includes\\file.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory in C:\\webserver\\Apache2\\home\\bobharri\\www\\includeTest.php on line 2 [Thu Dec 27 16:19:30 2007] [error] [client 127.0.0.1] PHP Warning: include() [<a href='function.include'>function.include</a>]: Failed opening '\\home\\bobharri\\includes\\file.php' for inclusion (include_path='.;C:\\php5\\pear') in C:\\webserver\\Apache2\\home\\bobharri\\www\\includeTest.php on line 2 This is the same error message I get in the browser. Here is the code I am trying to execute: <?php include "\home\bobharri\includes\file.php"; ?> I am trying to get it to see the file in the directory C:\webserver\Apache2\home\bobharri\includes My live server has the document root \home\bobharri\www\ My assumption is that if I copied the dir structure under my live server the php could read files relative to that server root. Maybe that was a bad assumption? Thank You Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted December 27, 2007 Share Posted December 27, 2007 The leading slash on the include path refers to the root of the current hard disk. That is correct for your live server, but not for your local computer. There are several ways to get this to work - 1) Use the defined constant base path that I mentioned above. 2) Add the path to your include folder to the include_path setting. 3) Try - include $_SERVER['DOCUMENT_ROOT'] . "/../includes/file.php"; 4) Create a set of folders on your local computer that is identical to your live server and configure the web server to use the new document folder. Try method #3 first. It will work on both systems. Edit: Corrected the \ to / direction in the path. Quote Link to comment Share on other sites More sharing options...
anmdei34 Posted December 27, 2007 Author Share Posted December 27, 2007 Thanks Very Much, #3 worked perfectly. it was the /.. part in the path I hadn't figured out. I guess this takes you up to a parent directory? Thank Again Problem Solved Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.