note 40029 deleted from function.filesize by tomsommer

From: Date: Wed, 01 Sep 2004 17:31:06 +0000
Subject: note 40029 deleted from function.filesize by tomsommer
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-75871@lists.php.net to get a copy of this message
Note Submitter: setec at freemail dot it ---- This code is usefull if you want not to use a lot of bandwidth and time to get the remote file size. <?php function remote_file_size ($url) { $head = ""; $url_p = parse_url($url); $host = $url_p["host"]; $path = $url_p["path"]; $fp = fsockopen($host, 80, $errno, $errstr, 20); 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 ($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 = substr($header, strlen($s)); break; } } return $return; } print ("Google logo is " . remote_file_size ("http://www.google.it/intl/it_it/images/logo.gif") . " bytes!"); ?>

« previous php.notes (#75871) next »