File download from server in php. Why the browser thinks the file size is bigger than it is?

$this->file_size equal filesize($this->file_addr) , and this 1163748924 (1,08 GB)

But the browser thinks the file is 1.16.

I see that if the number of bytes to transfer in Gigabytes by dividing by 1024, you get a 1.08 (actual file size), but if by dividing by 1000, we get to 1.16. Given to browser (int)$file_size/1024/1024/1024*1000*1000*1000 - he saw 1.08 GB, but it has no effect.

If the Content-length header to remove, the download works.
With the files that are 500 MB, 50 MB and less is working. The file size of 1.08, or 1.16, 1,27 GB found the described problem.

The problem is this: the server gives the browser the file to the end and stops as it should. But the Browser thinks that the file is not transmitted to the end and believes that the transfer failed. The size of the downloaded file is of 1.08 and it opened quietly.

This assumption appeared after the file is transferred to the end, the browser is expecting something else from the server, and server just shuts down.

Here is the server code:
header('Content-Description: File Transfer');
 header('Content-Type: application/octet-stream');
 header('Content-Disposition: attachment; filename="'.$this->file_name.'"');
 header('Content-Length:' . $this->file_size);

 ini_set('output_buffering', 0);
 ini_set('zlib.output_compression', 0);

 $handle = fopen($this->file_addr, "rb");
 while (!feof($handle)){
 echo fread($handle, 8192);
 ob_flush(); // flush output

Here's the headlines:
no-store, no-cache, must-revalidate, post-check=0, pre-check=0
File Transfer
attachment; filename="Файл_1.tif"
Wed, 18 May 2016 13:35:20 GMT
Thu, 19 Nov 1981 08:52:00 GMT
July 9th 19 at 13:15
3 answers
July 9th 19 at 13:17
In General, the question may answer in September:
the line "ob_end_flush();"
and "ob_flush();" did not work out and cut down the error. As a result, the size of the file that is issued to a browser, has increased (as in the body of the file in addition to the file was full of rows with php errors).
Something like that.

Hence: if you download the file it turns out more than it weighs on the server, then check, what there such in the content of the file unnecessary.
July 9th 19 at 13:19
Maybe $this->file_size for some reason doesn't match with real size of $this->file_addr ?
And try removing header('Accept-Ranges: bytes');, you download not have to implement.
Just in case I will add the link can come in handy.
Assumed that $this->filesize is not correct. Replaced head-on filesize($this->file_addr).
The result is the same.
The reference was read previously. Thank you. Does not help.

I guess in the end if something goes into the browser, or the end of file is not going away. - Sadie98 commented on July 9th 19 at 13:22
"Accept-Ranges: bytes" removed? - Daphne_Roob commented on July 9th 19 at 13:25
Yes - Sadie98 commented on July 9th 19 at 13:28
View (and show us) the headers from the server via the "developer Tools".
Browser does not just expect the larger size.

And try adding header('Content-Transfer-Encoding: binary'); in case he suddenly substituted "chunked" - there is just extra expected bytes wormed.

At the same time describe what you have nginx + apache or php-fpm or the like. - Daphne_Roob commented on July 9th 19 at 13:31
July 9th 19 at 13:21
Use nginx and x-accel-redirect

Find more questions by tags PHP