file_get_contents() 上的 PHP 路径

JCA*_*era 1 php

我需要用来file_get_contents()获取文件(file.php)中html页面(content.html)的内容,该文件位于如下目录中:

/content
- content.html
/functions
- file.php
Run Code Online (Sandbox Code Playgroud)

所以我尝试使用file_get_contents('../content/content.html')来获取 html 内容,但出现此错误:

failed to open stream: No such file or directory
Run Code Online (Sandbox Code Playgroud)

我想我可能使用了错误的路径。我能做些什么?

Kar*_*kak 6

始终使用$_SERVER['DOCUMENT_ROOT'] ,这样您就不必处理文件路径的问题。

尝试:

file_get_contents($_SERVER['DOCUMENT_ROOT'] .'/content/content.html');
Run Code Online (Sandbox Code Playgroud)