0

I have a shortcode to extract info from a file using a URL when this is requested by code says that file is 410 MB, but when this file is fully downloaded real file size is 390 MB, some way of getting file size 390 MB or a bit similar to end size?

<?php
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_NOBODY, TRUE);
$data = curl_exec($ch);
$size = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD);
curl_close($ch);
echo round( $size / '1000000', 2);
?>
Nasser Ali Karimi
  • 4,462
  • 6
  • 34
  • 77
  • 2
    Possible duplicate of [Remote file size without downloading file](https://stackoverflow.com/questions/2602612/remote-file-size-without-downloading-file) – Mohammad Nov 25 '18 at 10:03
  • @Mohammad problem is solved, error was in my size conversion, isn't '1000000' is '1048576' – EntrepreneurVE Nov 25 '18 at 10:06
  • No possible duplicate here, because the question is not how to retrieve the filesize of a remote file. The real question is how to convert bytes into megabyte. – Marcel Nov 25 '18 at 17:26

1 Answers1

0

Your byte conversion is wrong. It 's a math issue and not a php issue.

Since a single kilobyte (KB) are 1024 bytes you have to convert single bytes with the factor 1048576, because 1048576 bytes are 1 megabyte.

Have a look at the accepted answer of this question.

Marcel
  • 4,854
  • 1
  • 14
  • 24