1. Using file_get_contents ()
Copy CodeThe code is as follows:
$file = file_get_contents ($url);
echo strlen ($file);
?>
2. Using Get_headers ()
Copy CodeThe code is as follows:
$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 show
Warning:get_headers () [function.get-headers]: URL file-access is disabled in the server configuration
3. Using Fsockopen ()
Copy CodeThe code is as follows:
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;
}
}
?>
http://www.bkjia.com/PHPjc/328048.html www.bkjia.com true http://www.bkjia.com/PHPjc/328048.html techarticle 1. Use file_get_contents () to copy code as follows: PHP $file = file_get_contents ($url); Echo strlen ($file); 2. Use Get_headers () to copy the code as follows:? php $header _ ...