function | file size | remote file |header
PHP Gets the remote file size and information function (header header information gets)
Arisisi alixixi.com Development team to do a customer system, need to do remote download function, and real-time display progress bar effect.
So, you need to read the size information of the remote file beforehand, and then do the parameters of the live download progress bar.
function functions as follows, the call is simple, getfilesize ("Http://www.alixixi.com/download/xml.rar"), you can get the size of the remote file.
The following is a reference fragment: <?php function GetFileSize ($url) { $url = Parse_url ($url); if ($fp = @fsockopen ($url [' Host '],empty ($url [' Port ']): $url [' Port '], $error)) { Fputs ($fp, "get". Empty ($url [' path '])? ' /': $url [' path ']]. " Http/1.1\r\n "); Fputs ($FP, "Host: $url [host]\r\n\r\n"); while (!feof ($fp)) { $tmp = fgets ($FP); if (Trim ($tmp) = = ") { Break }else if (Preg_match ('/content-length: (. *)/si ', $tmp, $arr)) { return Trim ($arr [1]); } } return null; }else{ return null; } } Echo getfilesize ("Http://www.alixixi.com/download/xml.rar") ?> |
This function obtains the remote file size very well, regardless of the size of the remote file, the acquisition speed is completely unaffected.