Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
884 views
in Technique[技术] by (71.8m points)

php - require_once :failed to open stream: no such file or directory

I have this testing code in "PAGE A":

<?php
require_once('../mysite/php/classes/eventManager.php');
$x=new EventManager();
$y=$x->loadNumbers();
?>

"eventManager.php" has inside a require_once:

<?php
require_once('../includes/dbconn.inc');
class EventManager {...}
?>

My folders structure is this:

mysite/php/classes folder and includes folder

If i test PAGE A in a browser i receive:

Warning: require_once(../includes/dbconn.inc) [function.require-once]: failed to open stream: No such file or directory in C:wampwwwmysitephpclasseseventManager.php on line 3


Fatal error: require_once() [function.require]: Failed opening required '../includes/dbconn.inc' (include_path='.;C:php5pear') in C:wampwwwmysitephpclasseseventManager.php on line 3

where is the error?

Thanks Luca

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The error pretty much explains what the problem is: you are trying to include a file that is not there.

Try to use the full path to the file, using realpath(), and use dirname(__FILE__) to get your current directory:

require_once(realpath(dirname(__FILE__) . '/../includes/dbconn.inc'));

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...