1. Go to this page and download the library: Download nassiry/filesize-handler library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
nassiry / filesize-handler example snippets
use Nassiry\FileSizeUtility\FileSizeHandler;
$handler = FileSizeHandler::create()
->local('/path/to/file')
->binary();
// Get the formatted size
echo $handler->format(); // Example output: "1.23 MiB"
// Or use directly with echo
echo FileSizeHandler::create()
->local('/path/to/file')
->binary()
->format();
use Nassiry\FileSizeUtility\Sources\FileSourceInterface;
class CustomCloudSource implements FileSourceInterface
{
public function __construct(private string $apiKey, private string $filePath) {}
public function getSizeInBytes(): int
{
// Implement API logic to get file size
return 123456789;
}
}
$customSource = new CustomCloudSource('api-key', '/path/to/file');
// Once implemented, register your custom source using:
$handler = FileSizeHandler::create()
->from($customSource)
->binary();
echo $handler->format(); // Example output: "1.23 MiB"