可以用相对路径。require是相对当前文件目录的。

解决方案 »

  1.   

    require("file.php");
    require("dir/file.php");
    这样可以。但如果用
    require("./file.php");
    这样就不行。
      

  2.   

    可供参考:
    http://community.csdn.net/Expert/topic/4648/4648044.xml?temp=.8632013
      

  3.   

    楼上谢谢你的回答!
    require("file.php");
    require("dir/file.php");
    这样可以。但如果用
    require("./file.php");
    这样就不行。Gdj你可能没有看清我的问题,我的问题是有三个文件第一个和第二个有require语句,关键是其中的第二个文件中的require语句的require不是根据他的文件位置出发的相对路径,而是根据第一个文件的相对路径(因为第一个文件用了require来包含第二个文件!),我其他目录夹里的文件就不能正确调用这第二个文件了,因为路径会出错!
      

  4.   

    是三个文件没错啊。文件二中用require("file.php");这样写法是基于文件二所在位置而不是文件一。
      

  5.   

    1、根据部分同志的讨论,好的程序结构不应当有这样的多层嵌套;
    2、如果需要的这样的引用,可以以__FILE__作为脚本基本路径进行引用。
      

  6.   

    如果文件二用require("./file.php")这种写法时才是基于文件一的位置。用require("file.php");这种写法的文件不管怎么被别的文件require都能正确运行。
      

  7.   

    第一个和第二个有require语句,关键是其中的第二个文件中的require语句的require不是根据他的文件位置出发的相对路径,而是根据第一个文件的相对路径(因为第一个文件用了require来包含第二个文件!),我其他目录夹里的文件就不能正确调用这第二个文件了,因为路径会出错!-----------------------------------------------it won't happen.
    the require function in the second page uses  the directory relative to the second page.
      

  8.   

    Warning: require_once(../util/die_out.php) [function.require-once]: failed to open stream: No such file or directory in C:\ApacheGroup\Apache2\www\mywan\class\Gamer.class.php on line 3我要上一层目录,所以用了../util/die_out.php
      

  9.   

    要上一层不行。要上一层的用__FILE__自己处理
      

  10.   

    __file__得到的是个绝对路径C:\ApacheGroup\Apache2\www\mywan\class\Gamer.class.php我该如何处理??xuzuning(唠叨)大哥:一般的是根据util,是什么意思啊??!
      

  11.   

    做了一个函数<?php
    /*
     * Created on 2006-6-13
     *
     * To change the template for this generated file go to
     * Window - Preferences - PHPeclipse - PHP - Code Templates
     */
    function smarty_require($path,$abs_path){
      preg_match("/([.|\/]*)(.*)/",$path,$matches);
      //var_dump($path);
     
      $link=split("\\\\", $abs_path);
      //var_dump($link);
     
      if($matches[1]){
      $step=split("/", $matches[1]);
    }
      //var_dump($matches[1]."<br>");
      //var_dump($step);
     
      $length=-1;
      $max=count($step); 
     
      for($i=0;$i<$max;$i++){
      if($step[$i]=='..'){
      $length--;
      }
      }
     
      $link=array_slice($link,0,$length);
      $result=implode("/",$link);
     
      echo ($result);
      if($matches[2]){
    $result=$result."/".$matches[2];
      }
    else{
    die("路径输入有误!");
    }

    require_once($result);
    }
    ?>
    smarty_require("../util/die_out.php",__FILE__);   //这样调用!但现在不知道如何能不能象php内置函数一样直接调用!
      

  12.   

    把你原来的
    require("../xx.php");
    改成这样就行了
    require(dirname(__FILE__)."/../xx.php");