Php obtains the size of a remote file. the code is as follows: *** function: obtains the size of the remote file. the returned value is in the unit of * functionget_fileSize ($ url) {if (! Isset ($ url) | trim ($ url) {return;} ob_start (); $ chcurl_init ($ url); curl_setopt ($ ch, CURLOPT_HEADER, 1 ); use curl_s php to obtain the size of a remote file. the code is as follows:
/*
** Function: obtains the size of a remote file. the returned value is in bytes.
*/
Function get_fileSize ($ url ){
If (! Isset ($ url) | trim ($ url) = ''){
Return '';
}
Ob_start ();
$ Ch = curl_init ($ url );
Curl_setopt ($ ch, CURLOPT_HEADER, 1 );
Curl_setopt ($ ch, CURLOPT_NOBODY, 1 );
$ Okay = curl_exec ($ ch );
Curl_close ($ ch );
$ Head = ob_get_contents ();
Ob_end_clean ();
$ Regex = '/Content-Length: \ s ([0-9]. + ?) \ S /';
$ Count = preg_match ($ regex, $ head, $ matches );
Return isset ($ matches [1]) & is_numeric ($ matches [1])? $ Matches [1]: '';
}