Why do I get a Warning and a Fatal error when I use ../?
When I use ../mysqlConnect.php
I get the following messages.
Warning: require_once(../mysqlConnect.php) [function.require-once]:
failed to open stream: No such file or directory in /home/content/etc...
Fatal error: require_once() [function.require]: Failed opening required
'../mysqlConnect.php' (include_path='.:/usr/local/php5/lib/php') in /home/con开发者_JAVA百科tent/etc...
When I use the directory name - mydir/mysqlConnect.php
- everything works fine.
require_once('../mysqlConnect.php')
asks PHP to look in the directory above the one your script is currently in for mysqlConnect.php
.
Since your connection file appears to be in a mydir
directory, require_once('mydir/mysqlConnect.php')
works because it looks in that directory, which is contained by the one it's currently in.
Visual representation (assuming script.php
is your script including that file):
dir/
subdir/ # PHP looks here for ../mysqlConnect.php
script.php
mydir/ # PHP looks here for mydir/mysqlConnect.php
mysqlConnect.php
Require is relative to the invoced script, not the script you call require() in. Use something like this to have an absolute path:
require(dirname(__FILE__) . '/../mysqlConnect.php');
In PHP 5 you can also use DIR.
because it doesn't find your file then. to give a more specific answer I need to see you file-/folder-structure
That's because you are not specifying the correct include path. ../
refers to parent directory. ../../
goes two directories back, ../../../
goes three of them back. If the mysqlConnect.php
file is present in the same folder as your script, you don't need to specify ../
in the include.
Make sure that you specify the correct path. You can easily check whether or not you are specifying correct path like:
if (file_exists('../mysqlConnect.php'))
{
echo 'Iam specifying the correct path !!';
}
else
{
echo 'Well, I am not :(';
}
精彩评论