Definition of the size of the removed file
At definition of the size of the removed file the large value has, what potential volume has a file.
It is possible to allocate the following problems{tasks} of definition of the size of the removed file:
1. Definition of the size of the small removed file (html, php, etc.)
2. Definition of the size of the big removed file (zip, rar, mp3, etc.)
Definition of the size of the small removed file
<? php
$filename = " http: // www.webobzor.net/index.php ";
$fh = fopen ($filename, "r");
while (($str = fread ($fh, 1024))! = null) $fsize + = strlen ($str);
echo " the Size of a file: ". $fsize;
?>
We open a file $filename, we read from him{it} the data fread on 1024 bajta until these data are not equal to zero (null). Simultaneously we determine length of the received data strlen and their sum $fsize.
Definition of the size of the big removed file
As you have already guessed, the method described above does not approach for the big files as thus what to receive the size of a file of it{him} it would be necessary to read completely, and it is equivalent to his{its} uploading on a local computer. Therefore for the removed files, the having big size, is used other approach based on reading meta tegov:
<? 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 the given situation the data not a file, and meta tegov which come back at his{its} opening are read. Thus function stream_get_meta_data returns data file which contains data on a file, including value of the size of a file:
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
It is necessary to find only teg Content-Length (the size of a file) and to count the data from a line.

|