Require()?? absolute path.[SOLVED]

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
james3302
Forum Commoner
Posts: 53
Joined: Thu Aug 02, 2007 11:11 am

Require()?? absolute path.[SOLVED]

Post by james3302 »

I need to use the require function but I need to use a absolute path such as g:\website\inetpub\wwwroot\php

Is that possible? Here the dir structure

PHP-under PHP is Area, Armis, Live
Area, Armis and LIve each have North South West folders.


There are files in each North South West folder that make a DB connection. The guy who made the files put the connection details in each file and I am wanting to make one file and require it. I am wanting to put it into the php folder so that all the files can call it. I have tried

require("g:\website\inetpub\wwwroot\php\SoutDBConnection.php");

and it did not work.
Last edited by james3302 on Mon Jul 07, 2008 7:18 am, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Unless the path is on a different drive from where PHP runs (getcwd()) you may want to set/add-to the include path in php.ini instead.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

The code you have should work. I do it all the time. Verify that the file exists, and turn on error reporting.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
james3302
Forum Commoner
Posts: 53
Joined: Thu Aug 02, 2007 11:11 am

include in php.ini

Post by james3302 »

not every php file needs this file though. If I include it in the php.ini file then will every php file run it?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

You would only set the path of the file in the php.ini, not the file itself. Then, to simply include the file you would do

Code: Select all

include 'SoutDBConnection.php';
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Re: include in php.ini

Post by feyd »

james3302 wrote:not every php file needs this file though. If I include it in the php.ini file then will every php file run it?
You wouldn't set the full path to the file, only the path (without the filename.) Including would then be simply asking for the filename.
james3302
Forum Commoner
Posts: 53
Joined: Thu Aug 02, 2007 11:11 am

on a different drive

Post by james3302 »

PHP is installed on the C drive and the php files are on the G drive

and how do you turn on error reporting?
james3302
Forum Commoner
Posts: 53
Joined: Thu Aug 02, 2007 11:11 am

okay im back

Post by james3302 »

Had some server issues but Im back to working on this. The HD is partitioned into a C drive and a G drive. PHP is installed on the C drive and the website is on the G drive. If you suggest adding something to the php.ini file then please give me an example of how to add it. or any other suggestions I can try.

I have

;include_path = ".c:\php\includes"

which means its commented out, I just change that to

include_path = ".g:\website\..."

and then in the files use require(SouthDBConnection.php)
james3302
Forum Commoner
Posts: 53
Joined: Thu Aug 02, 2007 11:11 am

Well

Post by james3302 »

The absolute path worked this time. Last time it did not(that's why I posted this here). I can not take the line out of the php.ini file.
Post Reply