在PHP的require函数中返回基本url
在调用PHP的require函数时,如何获取基本url 我的文件位于:在PHP的require函数中返回基本url,php,path,require,Php,Path,Require,在调用PHP的require函数时,如何获取基本url 我的文件位于: www.mywebsite.com/folder_1/file.php 在我的服务器中,它位于: /folder_1/file.php 我想使用PHP require函数访问该文件,但似乎无法访问 我已经试过: require 'http://www.mywebsite.com/folder_1/file.php'; 及 需要“../folder_1/file.php” 我的视图(我放置require函数的位置)位于
www.mywebsite.com/folder_1/file.php
在我的服务器中,它位于:
/folder_1/file.php
我想使用PHP require函数访问该文件,但似乎无法访问
我已经试过:
require 'http://www.mywebsite.com/folder_1/file.php';
及
需要“../folder_1/file.php”
我的视图(我放置require函数的位置)位于
/application/innerdirectory/another_innerdirectory/another_dir/view_directory/view.php
我的文件的正确路径是什么?试试这个
require_once(__DIR__."/folder_1/file.php");
或
您可以为此使用
文档\u ROOT
:
require $_SERVER['DOCUMENT_ROOT'] . 'folder_1/file.php';
请记住,require是从服务器端工作的,所以在尝试包含http://
文件时,您不会期望很好的结果
require $_SERVER['DOCUMENT_ROOT'] . 'folder_1/file.php';