Get filesize in PHP
Here's a function to get the size of a file on a server in PHP.
function get_filesize($url,$thereturn) {
if (substr($url,0,4)=='http') {
$x = array_change_key_case(get_headers($url, 1),CASE_LOWER);
$x = $x['content-length'];
} else {
$x = @filesize($url);
}
if (!$thereturn) {
return $x;
} elseif($thereturn == 'mb') {
return round($x / (1024*1024),2);
} elseif($thereturn == 'kb') {
return round($x / (1024),2);
}
}
I'm not sure where I got this exactly, I'm guessting http://www.php.net. So credits to the original author.
function get_filesize($url,$thereturn) {
if (substr($url,0,4)=='http') {
$x = array_change_key_case(get_headers($url, 1),CASE_LOWER);
$x = $x['content-length'];
} else {
$x = @filesize($url);
}
if (!$thereturn) {
return $x;
} elseif($thereturn == 'mb') {
return round($x / (1024*1024),2);
} elseif($thereturn == 'kb') {
return round($x / (1024),2);
}
}
I'm not sure where I got this exactly, I'm guessting http://www.php.net. So credits to the original author.


