Today, I shared a php file size unit conversion method for everyone. I was planning to find and paste it in Baidu. but after searching for it for half a day, I decided to write it myself.
Today, I shared a php file size unit conversion method for everyone. I was planning to find and paste it in Baidu. but after searching for it for half a day, I decided to write one myself:
The following is the conversion code of the shared size unit: PHP file size unit conversion Source Code Download
PHP code
- /*
* Version: Test version
* Author: Wood
* Createtime: 2010.7.13
* Homepage: http://www.9streets.cn
* Tool: http watch
* More in my homepage
*/
- // Convert the file size by unit
- $ Size = "5120 ";
- Function check_str ($ size, $ k)
- {
- If (strpos ($ size, $ k ))
- {
- $ Y = 1;
- Return $ Y;
- }
- Else
- {
- $ Y = 2;
- Return $ Y;
- }
- }
- Function getsize ($ size)
- {
- If (check_str ($ size, m) = 1)
- {
- $ Size = sprintf ("% u", $ size );
- $ Size = ($ size * 1024). "k ";
- Return $ size;
- }
- Elseif (check_str ($ size, k) = 1)
- {
- $ Size = sprintf ("% u", $ size );
- $ Size = "$ size". "k ";
- Return $ size;
- }
- Elseif (check_str ($ size, k) = 2)
- {
- $ Size = sprintf ("% u", $ size );
- $ Size = ($ size/1024). "k ";
- Return $ size;
- }
- }
- Echo getsize ($ size );
Here, only Kb. mb is pushed based on the principle of other units. I will not talk about it here ....