Defining of the remote file's size
When you define the remote file’s size its potential size plays an important role.
We can point at the following tasks of the remote file’s size defining:
1. Defining the size of the small file (html, php etc)
2. Defining the size of the large file (zip, rar, mp3 etc)
Defining the size of the small file
<?php
$filename = "http://www.webobzor.net/index.php";
$fh = fopen($filename, "r");
while(($str = fread($fh, 1024)) != null) $fsize += strlen($str);
echo "File size: ".$fsize;
?>
Open the $filename file, read the fread data till that data isn’t equal null. Define the length of the received strlen data and their sum $fsize.
Defining the size of the large file
As you could understand we can’t use the listed above method for defining large files. We use another method based on the tags reading.
<?php
function fsize($path)
{
$fp = fopen($path,"r");
$inf = stream_get_meta_data($fp);
fclose($fp);
foreach($inf["wrapper_data"] as $v)
if (stristr($v,"content-length"))
{
$v = explode(":",$v);
return trim($v[1]);
}
}
$filesize = "http://www.res.goldpages.com.ru/downloads/icons/karbon.zip";
echo fsize($filesize);
?>
In that situation meta tags data are read, not file data. Here stream_get_meta_data function returns the data array that contains the information about file including the file size value:
HTTP/1.1 200 OK
Date: Fri, 20 Oct 2006 09:31:16 GMT
Server: Apache/1.3.37 (Unix) FrontPage/5.0.2.2623 PHP/4.4.4 with Suhosin-Patch mod_ssl/2.8.28 OpenSSL/0.9.7d-p1
Last-Modified: Thu, 12 Oct 2006 15:07:41 GMT
ETag: "61a0dc-54779-452e5a3d"
Accept-Ranges: bytes
Content-Length: 345977
Connection: close
The only thing we have to do is to find Content-Length tag and read data from the string



