包括作品,readfile 不
Include works, readfile doesn't
我在加载 html 文件时遇到奇怪的行为。 require_once
、include
等作品:
require_once 'suche.htm';
但readfile
或file_get_contents
不会
return file_get_contents('suche.htm');
Warning: readfile(suche.htm): failed to open stream: No such file or
directory in /var/www/vhosts/h...
Description
int readfile ( string $filename [, bool $use_include_path = false [, resource $context ]] )
注意第二个参数
use_include_path
You can use the optional second parameter and set it to TRUE, if you want to search for the file in the include_path, too.
file_get_contents
具有相同的参数。
如果您希望 readfile
/ file_get_contents
使用与 require
/ include
相同的路径分辨率,则需要将其设置为 true
。
请注意,readfile
不是 return 字符串,因此您不能在 htmlentities
中使用结果
更新
在我看来,相对于当前的 PHP 脚本文件,使用明确的文件路径要好得多。例如
file_get_contents(__DIR__ . '/../suche.htm');
我在加载 html 文件时遇到奇怪的行为。 require_once
、include
等作品:
require_once 'suche.htm';
但readfile
或file_get_contents
不会
return file_get_contents('suche.htm');
Warning: readfile(suche.htm): failed to open stream: No such file or directory in /var/www/vhosts/h...
Description
int readfile ( string $filename [, bool $use_include_path = false [, resource $context ]] )
注意第二个参数
use_include_path
You can use the optional second parameter and set it to TRUE, if you want to search for the file in the include_path, too.
file_get_contents
具有相同的参数。
如果您希望 readfile
/ file_get_contents
使用与 require
/ include
相同的路径分辨率,则需要将其设置为 true
。
请注意,readfile
不是 return 字符串,因此您不能在 htmlentities
更新
在我看来,相对于当前的 PHP 脚本文件,使用明确的文件路径要好得多。例如
file_get_contents(__DIR__ . '/../suche.htm');