本文整理汇总了PHP中FileHandler::returnBytes方法的典型用法代码示例。如果您正苦于以下问题:PHP FileHandler::returnBytes方法的具体用法?PHP FileHandler::returnBytes怎么用?PHP FileHandler::returnBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileHandler
的用法示例。
在下文中一共展示了FileHandler::returnBytes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testFileSize
public function testFileSize()
{
// file size
$this->assertEquals(FileHandler::filesize(0), '0Byte');
$this->assertEquals(FileHandler::filesize(1), '1Byte');
$this->assertEquals(FileHandler::filesize(386), '386Bytes');
$this->assertEquals(FileHandler::filesize(1023), '1023Bytes');
$this->assertEquals(FileHandler::filesize(1024), '1.0KB');
$this->assertEquals(FileHandler::filesize(2480), '2.4KB');
$this->assertEquals(FileHandler::filesize(1024 * 1024 - 1), '1024.0KB');
$this->assertEquals(FileHandler::filesize(1024 * 1024), '1.00MB');
$this->assertEquals(FileHandler::filesize(3 * 1024 * 1024 + 210 * 1024), '3.21MB');
// return bytes
$this->assertEquals(FileHandler::returnBytes('0B'), 0);
$this->assertEquals(FileHandler::returnBytes('1024B'), 1024);
$this->assertEquals(FileHandler::returnBytes('1K'), 1024);
$this->assertEquals(FileHandler::returnBytes('102.48K'), 1024 * 102.48);
$this->assertEquals(FileHandler::returnBytes('1M'), 1024 * 1024);
$this->assertEquals(FileHandler::returnBytes('1.12M'), 1024 * 1024 * 1.12);
$this->assertEquals(FileHandler::returnBytes('1023.99M'), 1024 * 1024 * 1023.99);
$this->assertEquals(FileHandler::returnBytes('1G'), 1024 * 1024 * 1024);
$this->assertEquals(FileHandler::returnBytes('12.02G'), 1024 * 1024 * 1024 * 12.02);
}
示例2: checkMemoryLoadImage
/**
* Check available memory to load image file
*
* @param array $imageInfo Image info retrieved by getimagesize function
* @return bool true: it's ok, false: otherwise
*/
function checkMemoryLoadImage(&$imageInfo)
{
if (!function_exists('memory_get_usage')) {
return true;
}
$K64 = 65536;
$TWEAKFACTOR = 2.0;
$channels = $imageInfo['channels'];
if (!$channels) {
$channels = 6;
}
//for png
$memoryNeeded = round(($imageInfo[0] * $imageInfo[1] * $imageInfo['bits'] * $channels / 8 + $K64) * $TWEAKFACTOR);
$availableMemory = FileHandler::returnBytes(ini_get('memory_limit')) - memory_get_usage();
if ($availableMemory < $memoryNeeded) {
return false;
}
return true;
}