Image size output by php
<?php
echo number_format($_FILES['photo']['size']/1024/1024,4,'.','');
?>
Here is the format to view the file size. At the beginning file size will shown as byte when we will write the code as follows, echo number_format($_FILES['photo']['size']);
We know 1024 byte = 1kb. So if we want to represent the size as kilobyte format we have to divide the size by 1024 so the code will be like that, echo number_format($_FILES['photo']['size']/1024);
But if we want to show the file size as megabyte format we have to divide this again by 1024 cause we know 1024kb = 1mb. And the coding will be like that, echo number_format($_FILES['photo']['size']/1024/1024);
There is a problem if you divide 100/1024 that means if you divide 100kb by 1024kb to convert megabyte you will get out put 0. Cause after point values are not printing. So what is the solution to get the values after point. Here is your code given below,
echo number_format($_FILES['photo']['size']/1024/1024,4); here 4 is ordering that the output will be print till four digit after '.'(point).
And if we want to change the point by any kind of strings we have add two more steps like that.
echo number_format($_FILES['photo']['size']/1024/1024,4,'.','');
Here inside the first single quotation you have to define which string you want to print instead of point. And the second single quotation will empty otherwise you will get error message.
echo number_format($_FILES['photo']['size']/1024/1024,4,'.','');
?>
Here is the format to view the file size. At the beginning file size will shown as byte when we will write the code as follows, echo number_format($_FILES['photo']['size']);
We know 1024 byte = 1kb. So if we want to represent the size as kilobyte format we have to divide the size by 1024 so the code will be like that, echo number_format($_FILES['photo']['size']/1024);
But if we want to show the file size as megabyte format we have to divide this again by 1024 cause we know 1024kb = 1mb. And the coding will be like that, echo number_format($_FILES['photo']['size']/1024/1024);
There is a problem if you divide 100/1024 that means if you divide 100kb by 1024kb to convert megabyte you will get out put 0. Cause after point values are not printing. So what is the solution to get the values after point. Here is your code given below,
echo number_format($_FILES['photo']['size']/1024/1024,4); here 4 is ordering that the output will be print till four digit after '.'(point).
And if we want to change the point by any kind of strings we have add two more steps like that.
echo number_format($_FILES['photo']['size']/1024/1024,4,'.','');
Here inside the first single quotation you have to define which string you want to print instead of point. And the second single quotation will empty otherwise you will get error message.
Comments
Post a Comment