Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

php - 如何使用相对路径包含文件?(How to include a file using a relative path?)

I would like to include a file located in front/header/header.php from a front/user/login.php file.

(我想从front/user/login.php文件中包含位于front/header/header.php文件。)

How i can include header.php in login.php ?

(我如何在header.php中包含header.php?)

since it needs to step back from user folder and then enter to header folder.

(因为它需要从user文件夹后退,然后进入header文件夹。)

i tried :

(我试过了 :)

<?php include('/header/header.php'); ?>
<?php include('../header/header.php');?>
<?php include('../../header/header.php');?>
<?php include('header/./header.php');?>
<?php include('header/../header.php');?>
<?php include('front/header/./header.php');?>
<?php include('front/header/../header.php');?>
  ask by hameed Hamish translate from so

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

1 Answer

0 votes
by (71.8m points)

I think, you missed context of including path.

(我认为,您错过了包含路径的上下文。)

Try to use:

(尝试使用:)

include dirname(__FILE__) . '/../header/header.php';

It should helps.

(应该会有所帮助。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...