我有一个这样的结构:
currentFolder
currentFile.php
email
email.php
我在文件currentFile.php
中,需要包含email.php
文件。
我已经尝试包括email/email.php
和/email/email.php
,但两者都不起作用?
将这个email.php
包含到currentFile.php
中的实际url是什么?
您需要用单引号或双引号将字符串括起来。像这样:
include 'email/email.php';
如果字符串以/
聊天器开头,PHP将只从文件系统的根目录中查找。(而不是相对于您当前的文件)
所以include '/email/email.php';
将在这里查看:
/email/email.php
include 'email/email.php';
将在此处显示:
/currentFolder/email/email.php
使用常量DIR来知道当前文件所在的目录。
包括DIR。'/email/email.php
在这种情况下最好使用__DIR__
。试试这个:
require_once __DIR__ . "'email'email.php"
但仅适用于PHP 5.3<