file size calculation question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
timberspine
Forum Newbie
Posts: 1
Joined: Tue Jun 24, 2008 9:25 pm

file size calculation question

Post by timberspine »

I'm dynamically creating a file by reading data from a database table. The data is stored in the table as a serialized array. Based on certain criteria, the query which gets the data from the table may return multiple rows; hence the resulting variable that holds this data is itself an array. I then spit the contents of this variable to the browser like so:

Code: Select all

<?
     header("Content-type: application/octet-stream");
     header("Content-Disposition: attachment; filename=\"file-name.txt\"");
     //header("Content-length: $size");
 
        foreach($buffer as $indata)
        {
            foreach(unserialize(stripslashes($indata)) as $rdata)
            {
                echo $rdata."\n";
            }
        }
?>
My question is, how do I calculate the value for $size??
WebbieDave
Forum Contributor
Posts: 213
Joined: Sun Jul 15, 2007 7:07 am

Re: file size calculation question

Post by WebbieDave »

Rather than echoing $rdata you can append it to some $variable then strlen($variable) but the web server should be calculating this and setting the Content-Length header itself.
Post Reply