-1

So, if i have a file that when its empty it requires a specific function, but if the file is NOT empty it will proceed to show (else) something else. This is currently the format I am using. I have tired several different manners and variations of doing so (from PHP Manual examples to StackOverFlow Q/A). What it is doing is showing me the else not the if, since the file is actually empty...

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

if(!empty($file))
{
some code here!
}
else
{
some other code here!
}
?>
j.otero
  • 45
  • 12

2 Answers2

7
<?
$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!
}
?>
-1

The problem seems to be that you are not actually loading the file before you check if it is empty.

You are only setting the variable $file to the string 'config/config2.php' not actually loading the file.

Before running your if statement do this:

$file = file_get_contents('config/config2.php');

or look into this: http://php.net/manual/en/function.fopen.php

bobkingof12vs
  • 660
  • 5
  • 22