Go Back   Webmaster Forum > Development > Programming > PHP
REMOVE the ads below !
Reply
 
LinkBack Thread Tools
  # 1 (permalink)
Old
Senior Geek
Posts: 559
Join Date: Nov 2007
iTrader: (0)
Location: Romania
Checking a size of a url ! - 11-30-2007

This function will return the size (in bytes) of a given URL.
PHP Code:
$fp = @fsockopen($host80$errno$errstr20); 
   if(!
$fp)  
   { return 
false; }  
   else  
   { 
       @
fputs($fp"HEAD ".$url." HTTP/1.1\r\n"); 
       @
fputs($fp"HOST: dummy\r\n"); 
       @
fputs($fp"Connection: close\r\n\r\n"); 
       
$headers ""
       while (!@
feof($fp)) { 
           
$headers .= @fgets ($fp128); 
       } 
   } 
   @
fclose ($fp); 
   
$return false
   
$arr_headers explode("\n"$headers); 
   foreach(
$arr_headers as $header) { 
       
$s "Content-Length: "
       if(
substr(strtolower ($header), 0strlen($s)) == strtolower($s)) { 
           
$return trim(substr($headerstrlen($s))); 
           break; 
       } 
   }  
   return 
$return


//File size of Google Image 
$size check_url_size('http://www.google.com/images/logo_sm.gif'); 
echo 
"Google Small Image Size is: $size bytes"
?> 
[/size][/font]
Reply With Quote
  # 2 (permalink)
Old
The Computer Addict !
Posts: 1,980
Join Date: Feb 2007
iTrader: (0)
Location: Bhopal (MP, India)
Re: Checking a size of a url ! - 11-30-2007

Thank you for posting,
but the code you have given is incomplete.

The correct code for accomplishing it is :
PHP Code:
<?
function check_url_size($url){   

   
$head "";   
   
$url_p parse_url($url);   
   
$host $url_p["host"];   
   
$path $url_p["path"];   

$fp = @fsockopen($host80$errno$errstr20);   
   if(!
$fp)   
   { return 
false; }   
   else   
   {   
       @
fputs($fp"HEAD ".$url." HTTP/1.1rn");   
       @
fputs($fp"HOST: dummyrn");   
       @
fputs($fp"Connection: closernrn");   
       
$headers "";   

       while (!@
feof($fp)) {   
           
$headers .= @fgets ($fp128);   
       }   
   }   
   @
fclose ($fp);   

   
$return false;   

   
$arr_headers explode("n"$headers);   

   foreach(
$arr_headers as $header) {   
       
$s "Content-Length: ";   

       if(
substr(strtolower ($header), 0strlen($s)) == strtolower($s)) {   
           
$return trim(substr($headerstrlen($s)));   
           break;   
       } 
  
   }   

   return 
$return;   

}   

//File size of Google Image   

$size check_url_size(&#8216;http://www.google.com/images/logo_sm.gif’);   

echo "Google Small Image Size is: $size bytes";

?>
Source : PHP - 100% Free PHP Scripts, Download & Use - ComputerEducationWorld.com

Thanx,
Shadab.

Last edited by Shadab : 11-30-2007 at 03:23 PM.
Reply With Quote
  # 3 (permalink)
Old
Senior Geek
Posts: 559
Join Date: Nov 2007
iTrader: (0)
Location: Romania
Re: Checking a size of a url ! - 11-30-2007

Sorry ! My mistake
Reply With Quote
  # 4 (permalink)
Old
Regular Geek
Posts: 308
Join Date: Nov 2007
iTrader: (0)
Re: Checking a size of a url ! - 12-01-2007

Thanks for this guys
Reply With Quote
  # 5 (permalink)
Old
Promotion Team Leader
Posts: 1,403
Join Date: Aug 2007
iTrader: (0)
Location: Sujangarh (Rajasthan,India)
Re: Checking a size of a url ! - 12-01-2007

oh..
How to use it??


Bidding Directory| Webmaster Zone| Directory Point | Dierctory Blog
PR4
Bidding Directory | Blog of India
If Shadab is solution....I need my question back...

Reply With Quote
Reply


Thread Tools



Advertise Here for just $6 per month

vBulletin®, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd. | SEO by vBSEO | Skin developed by vBStyles.com