How can the filesize() function be used to determine the size of a remote file in PHP, and what limitations does it have?
To determine the size of a remote file in PHP, you can use the filesize() function in combination with file_get_contents() to fetch the file remotely and then get its size. However, this method has limitations such as requiring the remote file to be accessible via URL and potentially being slower due to network latency.
$url = 'https://www.example.com/remote-file.txt';
$file_contents = file_get_contents($url);
$file_size = strlen($file_contents);
echo "Size of remote file: " . $file_size . " bytes";