本文整理汇总了PHP中formatBytes函数的典型用法代码示例。如果您正苦于以下问题:PHP formatBytes函数的具体用法?PHP formatBytes怎么用?PHP formatBytes使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了formatBytes函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getModuleAttachments
public function getModuleAttachments($module_name, $filter, $page, $size, $order)
{
$table_name = ucfirst($module_name) . 'Attachments';
$_model = D($table_name);
if (!$order) {
$order = 'id desc';
}
$_model = $_model->where($filter)->order($order);
if ($page && $size) {
$_model->page($page, $size);
}
$res = $_model->select();
foreach ($res as $k => $v) {
if ($module_name == 'user') {
$res[$k]['related_name'] = '<a target="_blank" href="/user/detail/' . $v["user_id"] . '">' . M("UserRecommends")->where('id=' . $v['user_id'])->getField('name') . '</a>';
}
if ($module_name == 'project') {
$res[$k]['related_name'] = '<a target="_blank" href="/project/detail/' . $v["project_id"] . '">' . M("Projects")->where('id=' . $v['project_id'])->getField('title') . '</a>';
}
$res[$k]['create_time'] = substr($res[$k]['create_time'], 0, 16);
$res[$k]['size'] = formatBytes($res[$k]['size']);
if ($v['create_user_id'] < 2000) {
$res[$k]['create_user_name'] = M("Users")->where('id=' . $v['create_user_id'])->getField('realname');
} else {
$res[$k]['create_user_name'] = M("UserInfo")->where('id=' . $v['create_user_id'])->getField('name');
}
}
return $res;
}
示例2: writeZIP
function writeZIP($targetDir, $idC, $version)
{
global $log;
$zipFile = "Wazzup_{$idC}" . "_" . $version . "_" . MIG_GAME . "_" . date("Ymd") . ".zip";
// genero nombre para el zip
$i = 0;
$existe = TRUE;
while ($existe === TRUE) {
if (file_exists(ZIP_DIR . "/{$zipFile}")) {
$i++;
//$zipFile = date("Ymd")."_Wazzup_".WAZZUP_WALLPAPER."_$i.zip";
$zipFile = "Wazzup_{$idC}" . "_" . $version . "_" . MIG_GAME . "_" . date("Ymd") . "_{$i}" . "_" . ".zip";
} else {
$existe = FALSE;
}
}
// zipeo y muevo a carpeta de "envios"
$shellCmd = "cd " . $targetDir . "; zip -r ../../../../" . ZIP_DIR . "/{$zipFile} * ";
// echo '<li>Creando ZIP con: ' . $shellCmd.'</li>';
$log .= exec($shellCmd);
echo "<li> Zip " . ZIP_DIR . "/{$zipFile} generado exitosamente</li>";
$ds = filesize(ZIP_DIR . "/{$zipFile}");
$ds = formatBytes($ds);
return array('size' => $ds, 'path' => ZIP_DIR . "/{$zipFile}");
}
示例3: DrawUsersList
function DrawUsersList()
{
global $connection, $config;
echo "<div class='page-header'><h1>Gestione utenti dispense</h1></div>\n";
echo "<div class='btn-group'>\n <button type='button' class='btn btn-success' id='addnewuser'><span class='fa fa-plus'></span> Nuovo</button>\n <button type='button' class='btn btn-default' id='edituser'><span class='fa fa-edit'></span> Modifica</button>\n <button type='button' class='btn btn-default' id='enableuser'><span class='fa fa-check'></span> Abilita</button>\n <button type='button' class='btn btn-default' id='disableuser'><span class='fa fa-ban'></span> Disabilita</button>\n <button type='button' class='btn btn-danger' id='deletemultiuser'><span class='fa fa-remove'></span> Elimina</button>\n </div>\n <br><br>\n <table class='table table-hover'>\n <thead><tr>\n <th>Utente</th>\n <th>Nome completo</th>\n <th>Stato</th>\n <th>Email</th>\n <th>Spazio usato</th>\n <th>Spazio massimo</th>\n </tr></thead>";
$request = "SELECT * FROM teachers_users ORDER BY user ASC";
$result = $connection->query($request);
while ($line = $result->fetch_assoc()) {
//Draw table row
$name = $line["user"];
$fullname = $line["name"];
$mail = $line["email"];
if ($line["active"] == 1) {
$status = "<span class='fa fa-check'></span> Attivo";
} else {
$status = "<span class='fa fa-ban'></span> Disabilitato";
}
$max_space = formatBytes($line["max_user_space"] * 1073741824);
$space_percent = intval(getFolderSize("../" . $config->plugin_notes_engine_fpath . "/" . $name) / ($line["max_user_space"] * 1073741824) * 100);
$space_used = "<div class='progress' style='min-width: 175px;'><div class='progress-bar' role='progressbar' aria-valuenow='{$space_percent}' aria-valuemin='0' aria-valuemax='100' style='width: {$space_percent}%; min-width: 20px;'>{$space_percent}%</div></div>";
if ($space_percent > 90) {
$class = "class='danger'";
} elseif ($space_percent > 80) {
$class = "class='warning'";
} else {
$class = "";
}
echo "<tr {$class}>\n <td><input type='checkbox' id='select-{$name}' value='{$name}'> <a href='index.php?module=notes-engine&arg={$name}'>{$name}</a></td>\n <td>{$fullname}</td>\n <td>{$status}</td>\n <td>{$mail}</td>\n <td>{$space_used}</td>\n <td>{$max_space}</td>\n </tr>";
}
echo "</table></div>";
}
示例4: displayRuns
function displayRuns($resultSet, $title = "")
{
echo "<div class=\"runTitle\">{$title}</div>\n";
echo "<table id=\"box-table-a\" class=\"tablesorter\" summary=\"Stats\"><thead><tr><th>Timestamp</th><th>Cpu</th><th>Wall Time</th><th>Peak Memory Usage</th><th>URL</th><th>Simplified URL</th></tr></thead>";
echo "<tbody>\n";
while ($row = XHProfRuns_DefaultXHPROFGUI::getNextAssoc($resultSet)) {
$c_url = urlencode($row['c_url']);
$url = urlencode($row['url']);
$html['url'] = htmlentities($row['url'], ENT_QUOTES, 'UTF-8');
$html['c_url'] = htmlentities($row['c_url'], ENT_QUOTES, 'UTF-8');
$date = date('M d H:i:s', (int) $row['timestamp']);
$row['cpu'] = printSeconds($row['cpu']);
$row['wt'] = printSeconds($row['wt']);
$row['pmu'] = formatBytes($row['pmu']);
echo "\t<tr><td><a href=\"?run={$row['id']}\">{$date}</a><br /><span class=\"runid\">(ID: {$row['id']})</span></td><td>{$row['cpu']}</td><td>{$row['wt']}</td><td>{$row['pmu']}</td><td><a href=\"?geturl={$url}\">{$html['url']}</a></td><td><a href=\"?getcurl={$c_url}\">{$html['c_url']}</a></td></tr>\n";
}
echo "</tbody>\n";
echo "</table>\n";
echo <<<SORTTABLE
<script type="text/javascript">
\$(document).ready(function()
{
\$("#box-table-a").tablesorter( {sortList: []} );
}
);
</script>
SORTTABLE;
}
示例5: scriptReturn
function scriptReturn($return, $buffer = false, $json = true)
{
global $initime;
if ($buffer) {
// start and end user output so this can happen without the user waiting
ob_end_clean();
header("Connection: close");
ignore_user_abort();
// optional
ob_start();
}
if ($json) {
$return['memory_usage'] = formatBytes(memory_get_usage());
$return['memory_peak_usage'] = formatBytes(memory_get_peak_usage());
$return['script_run_time'] = round((microtime(true) - $initime) * 1000);
header('Content-Type: application/json');
echo json_encode($return, JSON_NUMERIC_CHECK);
} else {
header('Content-Type: text/html');
echo htmlArray($return);
}
if ($buffer) {
$size = ob_get_length();
header("Content-Length: {$size}");
ob_end_flush();
// Strange behaviour, will not work
flush();
// Unless both are called !
}
}
示例6: displayFiles
function displayFiles($path)
{
echo "<table class='table table-hover file-list'>\n <thead><th>Nome</th><th>Dimensione</th><th>Ultima modifica</th></thead>";
$file_array = array_diff(scandir("../" . $path), array('..', '.', '.DS_Store'));
foreach ($file_array as $file) {
$url = "../" . $path . "/" . $file;
if (is_dir($url)) {
$name = $file;
$folder_path = $path . "/" . $file;
$size = formatBytes(getFolderSize($url), 1);
$date = date("d/m/Y", stat($url)['mtime']);
echo "<tr><td><span class='fa-stack fa-2x'><i class='fa fa-folder'></i></span> <a href='#' data-path=\"{$folder_path}\" class='file-list-folder'>{$name}</a>";
echo "<button type='button' class='btn btn-link pull-right lmb remove-folder tooltipped' data-toggle='tooltip' title='Elimina' data-path=\"{$folder_path}\"><i class='fa fa-remove'></i></button>";
echo "<button type='button' class='btn btn-link pull-right lmb edit-folder tooltipped' data-toggle='tooltip' title='Rinomina' data-path=\"{$folder_path}\"><i class='fa fa-edit'></i></button>";
echo "</td><td><span class='text-muted'>{$size}</span></td><td><span class='text-muted'>{$date}</span></td></tr>";
} else {
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$content_type = finfo_file($finfo, $url);
$file_icon = getFileTypeIcon($content_type, $file);
$size = formatBytes(filesize($url), 1);
$date = date("d/m/Y", filemtime($url));
$preview = canPreview($content_type);
if ($preview == "no") {
echo "<tr><td><span class='fa-stack fa-2x'><i class='fa {$file_icon}'></i></span> <a href=\"{$url}\" class='file-list' target='_blank'>{$file}</a>";
} else {
echo "<tr><td><span class='fa-stack fa-2x'><i class='fa {$file_icon}'></i></span> <a href='#' data-path=\"{$url}\" data-preview_mode='{$preview}' class='file-list-previewable'>{$file}</a>";
}
echo "<button type='button' class='btn btn-link pull-right lmb remove-file tooltipped' data-toggle='tooltip' title='Elimina' data-path=\"{$url}\"><i class='fa fa-remove'></i></button>";
echo "</td><td><span class='text-muted'>{$size}</span></td><td><span class='text-muted'>{$date}</span></td></tr>";
}
}
echo "</table>";
}
示例7: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
// get all thumbnails
$dir = Asset\Image\Thumbnail\Config::getWorkingDir();
$thumbnails = array();
$files = scandir($dir);
foreach ($files as $file) {
if (strpos($file, ".xml")) {
$thumbnails[] = str_replace(".xml", "", $file);
}
}
$allowedThumbs = array();
if ($input->getOption("thumbnails")) {
$allowedThumbs = explode(",", $input->getOption("thumbnails"));
}
// get only images
$conditions = array("type = 'image'");
if ($input->getOption("parent")) {
$parent = Asset::getById($input->getOption("parent"));
if ($parent instanceof Asset\Folder) {
$conditions[] = "path LIKE '" . $parent->getFullPath() . "/%'";
} else {
$this->writeError($input->getOption("parent") . " is not a valid asset folder ID!");
exit;
}
}
$list = new Asset\Listing();
$list->setCondition(implode(" AND ", $conditions));
$total = $list->getTotalCount();
$perLoop = 10;
for ($i = 0; $i < ceil($total / $perLoop); $i++) {
$list->setLimit($perLoop);
$list->setOffset($i * $perLoop);
$images = $list->load();
foreach ($images as $image) {
foreach ($thumbnails as $thumbnail) {
if (empty($allowedThumbs) && !$input->getOption("system") || in_array($thumbnail, $allowedThumbs)) {
if ($input->getOption("force")) {
$image->clearThumbnail($thumbnail);
}
$this->output->writeln("generating thumbnail for image: " . $image->getFullpath() . " | " . $image->getId() . " | Thumbnail: " . $thumbnail . " : " . formatBytes(memory_get_usage()));
$this->output->writeln("generated thumbnail: " . $image->getThumbnail($thumbnail));
}
}
if ($input->getOption("system")) {
$thumbnail = Asset\Image\Thumbnail\Config::getPreviewConfig();
if ($input->getOption("force")) {
$image->clearThumbnail($thumbnail->getName());
}
$this->output->writeln("generating thumbnail for image: " . $image->getFullpath() . " | " . $image->getId() . " | Thumbnail: System Preview (tree) : " . formatBytes(memory_get_usage()));
$this->output->writeln("generated thumbnail: " . $image->getThumbnail($thumbnail));
}
}
\Pimcore::collectGarbage();
}
}
示例8: writeHTMLFiles
/**
* @param $directory
* @param $files
*/
function writeHTMLFiles($directory, $files)
{
echo "Processing " . $directory . "\n";
$excludeFiles = [".DS_Store", "sign.time", "index.html", "."];
$contents = <<<END
<html>
<body>
<table>
<tr>
<th align='left'>Filename</th>
<th align='right'>Last modified</th>
<th align='right' style='padding-left: 100px'>Size</th>
</tr>
END;
foreach ($files as $file) {
// if ($file === "index.html") {
// continue;
// }
// if ($file === ".") {
// continue;
// }
if (in_array($file, $excludeFiles) == true) {
continue;
}
if ($file === "..") {
$contents .= "<tr><td colspan='3'>";
$contents .= "<a href='..'>Parent Directory</a>";
$contents .= "</td></tr>";
} else {
$contents .= "<tr><td>";
$filename = $directory . '/' . $file;
$file = htmlentities($file);
$contents .= "<a href='{$file}'>{$file}</a>";
$contents .= "</td><td>";
$contents .= date("j-M-Y H:i", filemtime($filename));
$contents .= "</td><td align='right'>";
if (is_dir($filename) == false) {
$contents .= formatBytes(filesize($filename));
}
$contents .= "</td></tr>";
}
}
$contents .= <<<END
</table>
</body>
</html>
END;
file_put_contents($directory . "/index.html", $contents);
}
示例9: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
// disable versioning
Version::disable();
// get all thumbnails
$thumbnails = [];
$list = new Asset\Video\Thumbnail\Config\Listing();
$items = $list->load();
foreach ($items as $item) {
$thumbnails[] = $item->getName();
}
$allowedThumbs = array();
if ($input->getOption("thumbnails")) {
$allowedThumbs = explode(",", $input->getOption("thumbnails"));
}
// get only images
$conditions = array("type = 'video'");
if ($input->getOption("parent")) {
$parent = Asset::getById($input->getOption("parent"));
if ($parent instanceof Asset\Folder) {
$conditions[] = "path LIKE '" . $parent->getFullPath() . "/%'";
} else {
$this->writeError($input->getOption("parent") . " is not a valid asset folder ID!");
exit;
}
}
$list = new Asset\Listing();
$list->setCondition(implode(" AND ", $conditions));
$total = $list->getTotalCount();
$perLoop = 10;
for ($i = 0; $i < ceil($total / $perLoop); $i++) {
$list->setLimit($perLoop);
$list->setOffset($i * $perLoop);
$videos = $list->load();
foreach ($videos as $video) {
foreach ($thumbnails as $thumbnail) {
if (empty($allowedThumbs) && !$input->getOption("system") || in_array($thumbnail, $allowedThumbs)) {
$this->output->writeln("generating thumbnail for video: " . $video->getFullpath() . " | " . $video->getId() . " | Thumbnail: " . $thumbnail . " : " . formatBytes(memory_get_usage()));
$video->getThumbnail($thumbnail);
$this->waitTillFinished($video->getId(), $thumbnail);
}
}
if ($input->getOption("system")) {
$this->output->writeln("generating thumbnail for video: " . $video->getFullpath() . " | " . $video->getId() . " | Thumbnail: System Preview : " . formatBytes(memory_get_usage()));
$thumbnail = Asset\Video\Thumbnail\Config::getPreviewConfig();
$video->getThumbnail($thumbnail);
$this->waitTillFinished($video->getId(), $thumbnail);
}
}
}
}
示例10: savePhoto
/**
* From ajax
*/
public function savePhoto()
{
$response = ['code' => 0, 'message' => trans('photo.error', ['size' => formatBytes()]), 'url' => ''];
if (\Request::hasFile('image')) {
if (!$this->photoRepository->imagesMetSizes(\Input::file('image'))) {
return json_encode($response);
}
$user = $this->userRepository->changeAvatar(\Input::file('image'));
if ($user) {
$response['code'] = 1;
$response['url'] = $user->present()->getAvatar(100);
}
}
return json_encode($response);
}
示例11: uploadBg
/**
* Ajax serving
*/
public function uploadBg()
{
$error = json_encode(['response' => 0, 'message' => trans('photo.error', ['size' => formatBytes()])]);
if (\Request::hasFile('image')) {
if (!$this->photoRepository->imagesMetSizes(\Input::file('image'))) {
return $error;
}
if ($image = $this->userRepository->changeDesignBg(\Input::file('image'), \Input::get('val.bg_image'))) {
return json_encode(['response' => 1, 'image' => \Image::url($image), 'imagePath' => $image]);
} else {
return $error;
}
}
return $error;
}
示例12: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$files = rscandir(PIMCORE_TEMPORARY_DIRECTORY . "/image-thumbnails/");
$savedBytesTotal = 0;
foreach ($files as $file) {
if (file_exists($file)) {
$originalFilesize = filesize($file);
\Pimcore\Image\Optimizer::optimize($file);
$savedBytes = $originalFilesize - filesize($file);
$savedBytesTotal += $savedBytes;
$this->output->writeln("Optimized image: " . $file . " saved " . formatBytes($savedBytes));
}
}
$this->output->writeln("Finished!");
$this->output->writeln("Saved " . formatBytes($savedBytesTotal) . " in total");
}
示例13: show_database
function show_database()
{
$db_size = 0;
echo "<h3>Status:</h3>";
$result = mysql_query("SHOW TABLE STATUS");
if ($result) {
while ($row = mysql_fetch_array($result)) {
$db_size += $row['Index_length'];
$db_size += $row['Data_length'];
}
echo "<p>The Grinder Server database '" . htmlentities(database_get_name(), ENT_QUOTES) . "' is currently " . htmlentities(formatBytes($db_size), ENT_QUOTES) . " in size.</p>";
mysql_free_result($result);
}
echo "<h3>Purge Database:</h3>";
echo "<p>Purge all crashes and nodes from the database.</p>";
echo "<div id='purge_db_button'>Purge</div>";
}
示例14: changePhoto
public function changePhoto()
{
$id = \Input::get('id');
$game = $this->gameRepository->get($id);
$response = ['code' => 0, 'message' => trans('photo.error', ['size' => formatBytes()]), 'url' => ''];
if (\Request::hasFile('image')) {
if (!$this->photoRepository->imagesMetSizes(\Input::file('image'))) {
return json_encode($response);
}
$image = $this->gameRepository->changePhoto(\Input::file('image'), $game);
if ($image) {
$response['code'] = 1;
$response['url'] = \Image::url($image, 100);
}
}
return json_encode($response);
}
示例15: listFiles
function listFiles($prefix)
{
date_default_timezone_set('UTC');
$location = "../download/product";
echo "<!-- listing files in {$location} with prefix {$prefix} -->";
if (false != ($dir = opendir($location))) {
while (false != ($file = readdir($dir))) {
if ($file != "." and $file != ".." and $file != "index.php") {
$files[] = $location . "/" . $file;
// put in array.
}
}
closedir($dir);
} else {
$location = "../../download/product";
if (false != ($dir = opendir($location))) {
while (false != ($file = readdir($dir))) {
if ($file != "." and $file != ".." and $file != "index.php") {
$files[] = $location . "/" . $file;
// put in array.
}
}
closedir($dir);
}
}
rsort($files);
$count = 0;
foreach ($files as $file) {
if ($count < 5) {
$refname = basename($file);
if (substr($refname, 0, strlen($prefix)) == $prefix) {
$count = $count + 1;
$stat = stat($file);
$date = date('Y-m-d', $stat['mtime']);
$size = formatBytes($stat['size']);
echo "<tr class='clickable'>";
echo "<td class='text-center'>{$date}</td>";
echo "<td><a href='http://eclipse.baeyens.it/download/product/{$refname}' target='_blank'><i class='glyphicon glyphicon-cloud-download'></i> {$refname}</a></td>";
echo "<td class='text-right'>{$size}</td>";
echo "</tr>";
}
}
}
}