IF文件是空的ELSE

j.o*_*ero 0 php if-statement

所以,如果我有一个文件,当它为空时它需要一个特定的功能,但如果该文件不是空的,它将继续显示(否则)其他东西.这是我目前正在使用的格式.我已经厌倦了几种不同的方式和变化(从PHP手册示例到StackOverFlow Q/A).它正在做的是向我显示其他而不是if,因为该文件实际上是空的...

<?
$file = 'config/config2.php';

if(!empty($file))
{
some code here!
}
else
{
some other code here!
}
?>
Run Code Online (Sandbox Code Playgroud)

小智 8

<?
$file = 'config/config2.php';

if(filesize($file)!=0)// NB:an empty 'looking' file could have a file size above 0
{
some code here!
}
else
{
some other code here!
}
?>
Run Code Online (Sandbox Code Playgroud)