readfile 不适用于串联

readfile not working with concatenation

1. 我正在使用 readfile 来打印文件的内容:

<?php readfile ('osta/css/themes/selected.txt'); ?>

2. 这非常有效。但是我现在需要使用ROOT_PATH。我这样添加:

<?php readfile (ROOT_PATH . 'osta/css/themes/selected.txt'); ?>

但没有打印任何内容。

3. 为了验证我的路径是否正确,我尝试了这个:

<a href="<?php echo (ROOT_PATH . 'osta/css/themes/selected.txt'); ?>">test</a>

这会为文件生成有效的 link。

我在第 2 步中做错了什么?

因为 ROOT_PATHhref 中工作,这意味着它是一个相对于网络服务器文档根目录的路径名,而不是真实文件系统的根目录。 readfile() 需要真实文件系统中的路径名,因此您需要添加文档根目录。

<?php readfile ($_SERVER['DOCUMENT_ROOT'] . ROOT_PATH . 'osta/css/themes/selected.txt'); ?>