Why is the filesize() function in PHP not suitable for remote files, and what alternative method can be used to determine the file size for remote downloads?

The filesize() function in PHP is not suitable for remote files because it requires the file path to be local. To determine the file size for remote downloads, you can use the get_headers() function to fetch the headers of the remote file and extract the "Content-Length" header, which indicates the size of the file.

$url = 'https://www.example.com/file.zip';
$headers = get_headers($url, 1);
$fileSize = $headers['Content-Length'];
echo "File size: " . $fileSize . " bytes";