Are there any potential pitfalls to be aware of when converting bytes to KB or MB in PHP?

When converting bytes to KB or MB in PHP, one potential pitfall to be aware of is integer overflow. If the size of the file is too large, the result of the conversion may exceed the maximum integer value in PHP, leading to incorrect calculations. To avoid this issue, you can use the PHP function `bcdiv()` to perform the division operation with arbitrary precision.

function bytesToKB($bytes) {
    return bcdiv($bytes, 1024, 2);
}

function bytesToMB($bytes) {
    return bcdiv($bytes, 1024 * 1024, 2);
}

// Example of converting bytes to KB and MB
$fileSizeInBytes = 5242880; // 5 MB
$fileSizeInKB = bytesToKB($fileSizeInBytes);
$fileSizeInMB = bytesToMB($fileSizeInBytes);

echo "File size: $fileSizeInBytes bytes\n";
echo "File size: $fileSizeInKB KB\n";
echo "File size: $fileSizeInMB MB\n";