Script to check the size of your webpage or image

Computer Education, Training & Tutorial Resources - ComputerEducationWorld.com
Home » Free Scripts » PHP »

Script to check the size of your webpage/image

Code (php)
  1.  
  2. <?
  3. function check_url_size($url){   
  4.  
  5.    $head = "";   
  6.  
  7.    $url_p = parse_url($url);   
  8.  
  9.    $host = $url_p["host"];   
  10.  
  11.    $path = $url_p["path"];   
  12.  
  13. $fp = @fsockopen($host, 80, $errno, $errstr, 20);   
  14.  
  15.    if(!$fp)   
  16.  
  17.    { return false; }   
  18.  
  19.    else   
  20.  
  21.    {   
  22.  
  23.        @fputs($fp, "HEAD ".$url." HTTP/1.1rn");   
  24.  
  25.        @fputs($fp, "HOST: dummyrn");   
  26.  
  27.        @fputs($fp, "Connection: closernrn");   
  28.  
  29.        $headers = "";   
  30.  
  31.        while (!@feof($fp)) {   
  32.  
  33.            $headers .= @fgets ($fp, 128);   
  34.  
  35.        }   
  36.  
  37.    }   
  38.  
  39.    @fclose ($fp);   
  40.  
  41.    $return = false;   
  42.  
  43.    $arr_headers = explode("n", $headers);   
  44.  
  45.    foreach($arr_headers as $header) {   
  46.  
  47.        $s = "Content-Length: ";   
  48.  
  49.        if(substr(strtolower ($header), 0, strlen($s)) == strtolower($s)) {   
  50.  
  51.            $return = trim(substr($header, strlen($s)));   
  52.  
  53.            break;   
  54.  
  55.        }   
  56.  
  57.    }   
  58.  
  59.    return $return;   
  60.  
  61. }   
  62.  
  63. //File size of Google Image   
  64.  
  65. $size = check_url_size(‘http://www.google.com/images/logo_sm.gif’);   
  66.  
  67. echo "Google Small Image Size is: $size bytes";
  68. ?>
  69.  

• • •
 



captcha PHP Script Free PHP captcha script free php
Website Design by WebWalas.com