how do I check if a text file is empty in php and if it is finished?

Asked

Viewed 476 times

1

I have a code that executes a simple query like this

select * from tabela where coluna1 = 'valor';

then I have a variable that brings a txt file

$filename = "C:/Programfile/arquivo.txt";

and then I make that condition below

if (file_exists($filename)) {
    rename($filename,$filename.".old");
}
$file = fopen($filename,"a+");

after that I do the query while

while ($row = mysql_fetch_array($sql))
{
            $content  = $row[0];
            $content .= "\r";
            $content .= "\n";   

            $result = fputs($file,$content);        

//break;
}
fclose($file);

the result of the query goes into the text file using vbs only I am with a problem that when the query has no record the text file becomes empty and I am not able to execute the script when the query does not return record someone can help me

I tried to do it and it didn’t work

if(filesize($filename)){
   exit;
}

or in place of the already put Exit return false e die() and it didn’t work.

  • 1

    I already solved the problem

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.