require_once( "../lib/utility.php" ) <- errors

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
mechamecha
Forum Commoner
Posts: 32
Joined: Thu May 31, 2007 8:49 pm

require_once( "../lib/utility.php" ) <- errors

Post by mechamecha »

Hello,

I am trying to require a file in a script that is located one directory back and in a separate folder, ie. "../lib/utility.php"

Each time I try to execute the php script w/ my browser, I am prompted w/ an error:

Warning: require_once(../lib/utility.php) [function.require-once]: failed to open stream: No such file or directory in C:\wamp\www\ah\data\registeration.php on line 8

Fatal error: require_once() [function.require]: Failed opening required '../lib/utility.php' (include_path='.;..;c:\wamp\php\include;c:\wamp\www\ah\lib') in C:\wamp\www\ah\data\registeration.php on line 8


The script I am trying to include is located int "C:\wamp\www\ah\lib"

I am running php on windows. I believe the include_path is set correctly. Does php not recognize the ".." notation?

I've hacked the script to ini_set() the exact location of the utility.php and require it directly, so I know its able to find the file.

Any help would be appreciated.

Thanks!
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Are you trying to do this within a file that is included in another?

Code: Select all

include dirname(__FILE__) . '/../lib/utility.php';
Also, you spelled "registration" wrong. n_n
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

I love it how people think that php lies to them...

If php tells you that the file specified does not exist... then it doesnt exist ... in the location you told it to look
mechamecha
Forum Commoner
Posts: 32
Joined: Thu May 31, 2007 8:49 pm

Post by mechamecha »

nickvd, no I'm not doing that w/i the file that needs to be included in others. I tried adding it and php gave me a error stating it could not include that directory.

I messed w/ it some more and it looks as though php does not like me adding "." or ".." in my require_once paths.

example,

require_once( 'userinfo.php' ); // works
require_once( './userinfo.php' ); //doesn't work
require_once( '../data/userinfo.php') //doesn't work

userinfo.php is located in c:/wamp/www/ah/data
registration.php is located in c:/wamp/www/ah/data

What am I doing wrong?
Do I have incorrect settings in my php.ini file?

THanks
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Again, '..' does not always correspond to the file making the inclusion. dirname(__FILE__) does.
Post Reply