New to programming. I am using fopen, fwrite fead to read and add content to a flat txt file. I can check to see if file_exists no problem, but if file exists but its empty... not sure how to check for that. Was hoping to at least get pointed in the right direction. Thanks :)

I think that you will need to read the file and see if you get anything.

Hi fuston05,

The PHP function filesize($filename) will return the size of a file :)

However are you looking for the feof($file_handle) function which tells you when you've finished reading from a file?

For example:


//open the file
$file = fopen("no_such_file", "r");

if ($file===false) {
//error opening the file

if (feof($file)) {
//the file is empty and we've only just opened it, we haven't even read anything from it yet

$contents = '';
while (!feof($file)) {

//read from the file
$line = fgets($file);
$contents .= $line;


//close the file



Awesome advise.. thanks a ton :)