PX : code

Remote File Size by Chad Lieberman
Download this code


<?

// Returns '0' if we can't open a connection to 
// the file OR we can't retrieve file size information.

function get_file_size ($url) 

   $url = parse_url($url); 
   $fp = fsockopen($url[host],80,$errno,$errstr,30); 
   socket_set_blocking($fp, TRUE); 

   // Can't open a connection // 
   if (! $fp) { return 0; } 

   fwrite($fp, "HEAD $url[path] HTTP/1.0\r\nHost: $url[host]\r\n\r\n"); 
   for($result = ""; !feof($fp); $result .= fread($fp, 10000000)); 
   fclose($fp); 

   if (preg_match("/content-length:\\s?(\\d+)/i", $result, $match)){ 
      return $match[1]; 
   } else { 
      return 0; 
   } 
}



echo get_file_size("http://www.google.com/images/hp0.gif");

?>

Comments or questions?
PX is running PHP 5.2.17
Thanks to Miranda Productions for hosting and bandwidth.
Use of any code from PX is at your own risk.