Just look at the code, it's good to know.
Copy CodeThe code is as follows:
Usage echo remote_filesize ($url, $user = ", $PW =");
$url = "http://www.aa.com/librarys/images/random/rand_11.jpg";//change your picture address here
Echo remote_filesize ($url, $user = ", $PW =");
function Remote_filesize ($uri, $user = ", $PW =")
{
Start output buffering
Ob_start ();
Initialize curl with given URI
$ch = Curl_init ($uri); Make sure we get the header
curl_setopt ($ch, Curlopt_header, 1); Make it a HTTP HEAD request
curl_setopt ($ch, curlopt_nobody, 1); If Auth is needed, does it here
if (!empty ($user) &&!empty ($PW))
{
$headers = Array (' Authorization:basic '. Base64_encode ($user. ': ' $pw));
curl_setopt ($ch, Curlopt_httpheader, $headers);
}
$okay = curl_exec ($ch);
Curl_close ($ch); Get the output buffer
$head = Ob_get_contents (); Clean the output buffer and return to previous//buffer settings
Ob_end_clean (); Gets the numeric value from the Content-length//field in the HTTP header
$regex = '/content-length:\s ([0-9].+?) \s/';
$count = Preg_match ($regex, $head, $matches); If there is a content-length field, its value//would now is in $matches [1]
if (Isset ($matches [1]))
{
$size = $matches [1];
}
Else
{
$size = ' unknown ';
}
$last _MB = Round ($size/(1024*1024), 3);
$last _kb = round ($size/1024,3);
Return $last _kb. ' KB/'. $last _mb. ' MB ';
}
The idea of the function is that curl gets the picture to the buffer, then the content-length information of the image is OK.