What are some best practices for accurately determining the file size in PHP?

When determining the file size in PHP, it's important to use the correct method to accurately calculate the size of the file. One common mistake is using the filesize() function, which may not work for files larger than 2GB. To accurately determine the file size, it's recommended to use the combination of fseek() and ftell() functions.

$file = 'example.txt';

$handle = fopen($file, 'r');
fseek($handle, 0, SEEK_END);
$filesize = ftell($handle);
fclose($handle);

echo "File size of $file is: $filesize bytes";