Filesize Implementation in PHP [Educational]

This is a custom implementation of filesize function in PHP, without using the built-in filesize. The file is read line by line and memory used for each line is accumulated. Here, strlen returns the bytes used for that line, in other words for the string $line. strlen does not return the length of the string in characters in general (i.e. for utf8 strings). To get the number of characters in an utf8 string, mb_strlen should be used instead of strlen.

This is only for educational purposes and it is better to use built-in filesize function.

Leave a comment

Your email address will not be published. Required fields are marked *