Hi,
I wanted to output the actual imagesize of the image.
An example: image on the server http://example.com/test.jpg will output 33,5 kb.
I had a look at http://dk2.php.net/manual/da/function.getimagesize.php but can't find the right solution. The url will only output width height bits channels... but not the size..
Thank you..
getimagesize()
Moderator: General Moderators
local file....
filesize();
remote file...
fsockopen(), read header Content Length <= no always given by server
fsockopen(), fread() complete file, strlen() file
fopen(), fread() complete file, strlen() file
file_get_contents(), strlen() file
A quick function...
filesize();
remote file...
fsockopen(), read header Content Length <= no always given by server
fsockopen(), fread() complete file, strlen() file
fopen(), fread() complete file, strlen() file
file_get_contents(), strlen() file
A quick function...
Code: Select all
<?
function normalize_size ( $file, $type )
{
$text = array ( ' Bytes (B)', ' Kilobytes (KB)', ' Megabytes (MB)' );
if ( $type == 1 )
{
$temp = filesize ( $file );
}
else
{
$temp = strlen ( file_get_contents ( $file ) );
}
$i = 0;
while ( $i <= 2 )
{
if ( $temp > 1024 )
{
$i++;
$temp = ( $temp / 1024 );
}
else
{
break;
}
}
return ( number_format ( $temp, 0, '', '.') . $text[$i] );
}
// usage
// type of file (1 = local, 2 = remote)
$type = 1;
// the local file
$file = './a.png';
// show the result
echo 'Local File: ' . $file . ', Size: ' . normalize_size ( $file, 1 );
echo '<br />';
// type of file (1 = local, 2 = remote)
$type = 2;
// the remote file
$file = 'http://www.google.com/intl/en/images/logo.gif';
// show the result
echo 'Remote File: ' . $file . ', Size: ' . normalize_size ( $file, 2 );
?>