【发布时间】:2018-07-01 18:55:00
【问题描述】:
我想在我的模板中包含一个 php 文件。但有时 php 文件不存在。 我尝试通过函数“file_exists”检查它,但它不起作用。
{if file_exists("`$plugin`/button.php")}
{include_php "`$plugin`/button.php"}
{/if}
致命错误:未捕获 --> Smarty 编译器:模板中的语法错误 第 456 行的“文件:/home/user/www/site/template/template.tpl” "{include_php "
$plugin/button.php"}" {include_php} 文件 '/button.php' 不可读
有没有办法检查php文件是否存在?
【问题讨论】:
-
这是什么:`$plugin`/button.php 真的是文件路径的名称吗?
-
@Andreas 我在 $plugin 变量中使用文件夹名称,它在文件路径中工作正常
-
it works ok in file path但在问题中你写了but it doesn't work.。是哪个? -
@Andreas 如果文件存在,它运行良好:) 但我想检查文件是否存在,因为如果文件不存在则会出现致命错误
-
确定不是 $plugin 变量为空或未设置导致错误?