Revision: 32656
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at October 1, 2010 08:12 by Abe
Initial Code
function get_remote_file_size($url) { $parsed = parse_url($url); $host = $parsed["host"]; $fp = @fsockopen($host, 80, $errno, $errstr, 20); if (!$fp) return false; else { @fputs($fp, "HEAD $url HTTP/1.1 "); @fputs($fp, "HOST: $host "); @fputs($fp, "Connection: close "); $headers = ""; while(!@feof($fp))$headers .= @fgets ($fp, 128); } @fclose ($fp); $return = false; $arr_headers = explode("\n", $headers); foreach ($arr_headers as $header) { $s = "Content-Length: "; if (substr(strtolower ($header), 0, strlen($s)) == strtolower($s)) { $return = trim(substr($header, strlen($s))); break; } } if ($return) { $size = round($return / 1024, 2); $sz = "KB"; // Size In KB if ($size > 1024) { $size = round($size / 1024, 2); $sz = "MB"; // Size in MB } $return = "$size $sz"; } return $return; }
Initial URL
http://www.weberdev.com/get_example-4610.html
Initial Description
Initial Title
Get Remote File Size
Initial Tags
Initial Language
PHP