Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php calculate file size after reading the content

Tags:

php

Using php i have contents of a file through file_get_contents() function. I want to calculate the size of the file using the contents. Is there a precise way to do it ?

I tried strlen(contents) , suggested in one of the answers , but there is quite difference in size returned and actual file size on computer.

Note : using ubuntu 12.04

EDIT : sorry for the waste of time guys, it seems the contents were base64_encode() which led to mismatch in sizes. I appreciate your time and effort. Sorry again.

like image 562
minas Avatar asked Mar 22 '23 07:03

minas


1 Answers

if strlen() doesn't return the length in bytes, check that 'function overloading' of mbstring is not enabled : http://www.php.net/manual/en/mbstring.overload.php

like image 198
voondo Avatar answered Apr 02 '23 09:04

voondo