Are there any potential pitfalls when using the filesize() function in PHP?

One potential pitfall when using the filesize() function in PHP is that it may return FALSE if the file does not exist or if there are permission issues. To avoid this issue, you can check if the filesize() function returns FALSE and handle it accordingly by displaying an error message or taking appropriate action.

$file = "example.txt";

$file_size = filesize($file);

if ($file_size === false) {
    echo "Error: Unable to get file size.";
} else {
    echo "File size: " . $file_size . " bytes";
}