[英]php include file only if existing
我正在测试php中的一些缓存代码:
if (is_readable($cachefile) && (time() - $cachetime
< filemtime($cachefile)))
{
include($cachefile);
[…]
它应该做什么:仅在$ cachefile已经存在时才运行include。 如果不是这样,应该继续尝试而不尝试包含$ cachefile。
它的作用:每次尝试加载$ cachefile时,因此会在不存在时创建php警告。
我不知道如何解决它,因为我尝试了通常会阻止include被执行的所有操作。 有人可以帮忙吗?
谢谢!
if(file_exists('file.php'))包括'file.php';
这样尝试
if (isset($cachefile) && ((time() - $cachetime) < filemtime($cachefile)))
{
include($cachefile);
}
您可以使用isset
或file_exists
函数,这是文档=>
http://php.net/manual/zh/function.file-exists.php
http://php.net/manual/zh/function.isset.php
注意 :在()中Wrap time() - $cachetime
$cachefile
,还要确保$cachefile
的网址正确
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.