PHP require file from top directory

后端 未结 6 645
梦毁少年i
梦毁少年i 2020-12-05 07:11

I have several subdomains contained in their own directory above my root site, and an assets folder in my root directory. For example:

/
/assets/
/forums/
/b         


        
6条回答
  •  再見小時候
    2020-12-05 08:15

    • suppose you have pgm1.php in www.domain.com/dir1/dir2/dir3/pgm1.php, which include or require 'dirA/inc/Xpto.php'.
    • and another pgm2.php in www.domain.com/dirZ1/dirZ2/pgm2.php, which include or require same 'dirA/inc/Xpto.php'.
    • and your Host configuration not authorize require/include 'http://www.domain.com/......'
    • So...you can use this, in both pgm1.php & pgm1.php, and REQUIRE or
      INCLUDE works !

      function rURI($p){
         for($w='',$i=1;$i<(count(explode('/',$_SERVER['PHP_SELF']))-1);$i++,$w.='../');return
         $w.$p; }
      

      require rURI('dirA/inc/Xpto.php'); // path from root

提交回复
热议问题