1. Use file_get_contents ()
Copy Code code as follows:
<?php
$file = file_get_contents ($url);
echo strlen ($file);
?>
2. Use of Get_headers ()
Copy Code code as follows:
<?php
$header _array = Get_headers ($url, true);
$size = $header _array[' content-length '];
Echo $size;
?>
PS:
Need to open allow_url_fopen!
If not open, it will display
Warning:get_headers () [function.get-headers]: URL file-access is disabled in the server configuration
3. Use of Fsockopen ()
Copy Code code as follows:
<?php
function Get_file_size ($url) {
$url = Parse_url ($url);
if (Empty ($url [' Host '])) {
return false;
}
$url [' port '] = Empty ($url [' post '])? : $url [' post '];
$url [' path '] = Empty ($url [' path '])? '/': $url [' path '];
$fp = Fsockopen ($url [' Host '], $url [' Port '], $error);
if ($fp) {
Fputs ($fp, "get". $url [' Path ']. "http/1.1\r\n");
Fputs ($FP, "Host:". $url [' Host ']. "\r\n\r\n");
while (!feof ($fp)) {
$str = fgets ($FP);
if (Trim ($str) = = ") {
Break
}elseif (Preg_match ('/content-length: (. *)/si ', $str, $arr)) {
return Trim ($arr [1]);
}
}
Fclose ($FP);
return false;
}else {
return false;
}
}
?>