Follow along with the video below to see how to install our site as a web app on your home screen.
Бележка: This feature may not be available in some browsers.
<?php
function getRemoteFileSize($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\r\n");
@fputs($fp, "HOST: $host\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 = 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;
}
//File size of Google Image
echo "Weberdev Logo Size : " . getRemoteFileSize('http://www.weberdev.com/images/BlueLogo150x45.gif');
echo "<br>A large sized Image : " . getRemoteFileSize('http://www.freewallpapers.to/wallpaper1/tiger.jpg');
?>
function remote_filesize($url){
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 1); //Взимаме хедърите пратени от сървъра
curl_setopt($ch, CURLOPT_NOBODY, 1); //НЕ взимаме съдържанието на файла
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Текста, който взехме се присвоява с curl_exec
$head = curl_exec($ch);
curl_close($ch);
$regex = '/Content-Length:\s([0-9].+?)\s/';
$count = preg_match($regex, $head, $matches);
return isset($matches[1]) ? $matches[1] : "...";
}