额 在一个工程(project)里的一个文件夹(db)有一个db_connect.php文件,另一个文件夹(dao)其中有个dao.php,dao.php include("../db/db_connect.php");在project工程里头还有一个usedb文件夹,在usedb文件夹里头还有一个news文件夹,news文件夹里有add.php,而add.php里include("../../dao/dao.php");在运行add.php却找不到db_connect.php
调试欢乐多
<?php$color = 'green';
$fruit = 'apple';?>test.php
<?phpecho "A $color $fruit"; // Ainclude 'vars.php';echo "A $color $fruit"; // A green apple?> <?phpfunction foo()
{
global $color; include 'vars.php'; echo "A $color $fruit";
}/* vars.php is in the scope of foo() so *
* $fruit is NOT available outside of this *
* scope. $color is because we declared it *
* as global. */foo(); // A green apple
echo "A $color $fruit"; // A green?> <?php/* This example assumes that www.example.com is configured to parse .php
* files and not .txt files. Also, 'Works' here means that the variables
* $foo and $bar are available within the included file. */// Won't work; file.txt wasn't handled by www.example.com as PHP
include 'http://www.example.com/file.txt?foo=1&bar=2';// Won't work; looks for a file named 'file.php?foo=1&bar=2' on the
// local filesystem.
include 'file.php?foo=1&bar=2';// Works.
include 'http://www.example.com/file.php?foo=1&bar=2';$foo = 1;
$bar = 2;
include 'file.txt'; // Works.
include 'file.php'; // Works.?>
.....................php文档里讲的很详细了,使用相对路径要注意路径的写法
相对路径中的当前路径问题,include(../db/db_connect.php)还没改
项目在
d:/www/盘下有以下内容
/db/db_connect.php
/dao/dao.php
/usedb/news/add.phpadd.php 定义路径
$path=dirname(dirname(__FILE__));//这里path不知道有没斜杠,忘记了.这里的path就是d:/www
//用常量最好,就是define('APPROOT',dirname(dirname(__FILE__)));下面$path 变成APPROOTinlcude $path."/dao/dao.php";dao.php里面应是include $path."/db/db_connect.php";
最好的是用绝对路径,不然你这个太烦了.
$filepath = dirname(dirname(__FILE__));
include ($path.'dao\dao.php');
或者
include ("dao\dao.php");
$filepath = dirname(dirname(__FILE__));
include ($filepath.'dao\dao.php');
$filepath = dirname(dirname(dirname(__FILE__)));
include ($filepath.'\dao\dao.php');