• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

PHP format_size函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中format_size函数的典型用法代码示例。如果您正苦于以下问题:PHP format_size函数的具体用法?PHP format_size怎么用?PHP format_size使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了format_size函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: format_size

function format_size($sizeb)
{
    if (strpos($sizeb, "|") !== false) {
        $size = "";
        $sizeb_split = split("\\|", $sizeb);
        for ($i = 0; $i < count($sizeb_split); $i++) {
            if ($i != 0) {
                $size .= '|';
            }
            $size .= format_size($sizeb_split[$i]);
        }
        return $size;
    } else {
        $sizekb = $sizeb / 1024;
        $sizemb = $sizekb / 1024;
        $sizegb = $sizemb / 1024;
        $sizetb = $sizegb / 1024;
        if ($sizeb > 1) {
            $size = round($sizeb, 2) . " B";
        }
        if ($sizekb > 1) {
            $size = round($sizekb, 2) . " KB";
        }
        if ($sizemb > 1) {
            $size = round($sizemb, 2) . " MB";
        }
        if ($sizegb > 1) {
            $size = round($sizegb, 2) . " GB";
        }
        if ($sizetb > 1) {
            $size = round($sizetb, 2) . " TB";
        }
        return $size;
    }
}
开发者ID:impakho,项目名称:DHT,代码行数:35,代码来源:Init.php


示例2: bootstrap_file_widget

/**
 * Overrides theme_file_widget().
 */
function bootstrap_file_widget($variables)
{
    $output = '';
    $element = $variables['element'];
    $element['upload_button']['#attributes']['class'][] = 'btn-primary';
    $element['upload_button']['#prefix'] = '<span class="input-group-btn">';
    $element['upload_button']['#suffix'] = '</span>';
    // The "form-managed-file" class is required for proper Ajax functionality.
    if (!empty($element['filename'])) {
        $output .= '<div class="file-widget form-managed-file clearfix">';
        // Add the file size after the file name.
        $element['filename']['#markup'] .= ' <span class="file-size badge">' . format_size($element['#file']->filesize) . '</span>';
    } else {
        $output .= '<div class="file-widget form-managed-file clearfix input-group">';
    }
    // Immediately render hidden elements before the rest of the output.
    // The uploadprogress extension requires that the hidden identifier input
    // element appears before the file input element. They must also be siblings
    // inside the same parent element.
    // @see https://www.drupal.org/node/2155419
    foreach (element_children($element) as $child) {
        if (isset($element[$child]['#type']) && $element[$child]['#type'] === 'hidden') {
            $output .= drupal_render($element[$child]);
        }
    }
    // Render the rest of the element.
    $output .= drupal_render_children($element);
    $output .= '</div>';
    return $output;
}
开发者ID:lcube45,项目名称:hyx,代码行数:33,代码来源:file-widget.func.php


示例3: showContent

function showContent($path)
{
    if ($handle = opendir($path)) {
        while (false !== ($file = readdir($handle))) {
            if ($file == '.' || $file == '..' || valid_extension($file)) {
                // echo "hidden<br>";
            } else {
                $fName = htmlspecialchars($file, ENT_QUOTES);
                $file = $path . "/" . $file;
                $file = htmlspecialchars($file, ENT_QUOTES);
                $fileurl = str_replace(" ", "%20", $file);
                if (is_file($file)) {
                    echo "<li class='music' data-icon='false'><a class='musicfile' href='#' data-src='" . $_ENV['domain'] . $fileurl . "'><h3>" . $fName . "</h3>" . "<p class='size ui-li-aside'> " . format_size(filesize($file)) . "</p></a></li>";
                } elseif (is_dir($file)) {
                    echo "<li class='folder'><a href='" . $_SERVER['SCRIPT_NAME'] . "?path=" . $file . "'>";
                    if (file_exists($file . "/" . $_ENV['coverart'])) {
                        $folderart = $_ENV['domain'] . $fileurl . "/" . $_ENV['coverart'];
                        echo "<img src='{$folderart}'>";
                    } else {
                        echo "<img src='images/jewelcase_empty.png'>";
                    }
                    echo "<h3>{$fName}</h3></a></li>";
                }
            }
        }
        closedir($handle);
    }
}
开发者ID:ramishi,项目名称:NMT-Cloudplayer,代码行数:28,代码来源:index.php


示例4: listFileJson

function listFileJson($dir, $start = 0, $limit = 500, $orderby = array())
{
    $arr = array();
    $arr['totalCount'] = 0;
    $arr['que_results'] = array();
    $arr['success'] = true;
    try {
        //$dir=ProdsDir::fromURI("rods://rods.tempZone:[email protected]:1247/tempZone/home/rods", false);
        $arr['totalCount'] = 0;
        $childdirs = $dir->getChildDirs($orderby);
        $arr['totalCount'] = $arr['totalCount'] + count($childdirs);
        foreach ($childdirs as $childdir) {
            $childstats = array();
            $childstats['id'] = $childdir->stats->id;
            $childstats['name'] = $childdir->stats->name;
            $childstats['size'] = -1;
            $childstats['fmtsize'] = "";
            $childstats['mtime'] = $childdir->stats->mtime;
            $childstats['ctime'] = $childdir->stats->ctime;
            $childstats['owner'] = $childdir->stats->owner;
            $childstats['type'] = 0;
            $childstats['ruri'] = $childdir->toURI();
            $arr['que_results'][] = $childstats;
        }
        $totalcount = 0;
        //$childfiles=$dir->getChildFiles($orderby,0, -1, $totalcount, true);
        $childfiles = $dir->getChildFiles($orderby);
        $arr['totalCount'] = $arr['totalCount'] + count($childfiles);
        foreach ($childfiles as $childfile) {
            $childstats = array();
            $childstats['id'] = $childfile->stats->id . '_' . $childfile->stats->rescname;
            $childstats['name'] = $childfile->stats->name;
            $childstats['size'] = $childfile->stats->size;
            $childstats['fmtsize'] = format_size($childfile->stats->size);
            $childstats['mtime'] = $childfile->stats->mtime;
            $childstats['ctime'] = $childfile->stats->ctime;
            $childstats['owner'] = $childfile->stats->owner;
            $childstats['rescname'] = $childfile->stats->rescname;
            $childstats['num_replica'] = $childfile->stats->num_replica;
            $childstats['typename'] = $childfile->stats->typename;
            $childstats['type'] = 1;
            $childstats['ruri'] = $childfile->toURI();
            $arr['que_results'][] = $childstats;
        }
        $_SESSION['acct_manager']->updateAcct($dir->account);
        $arr['que_results'] = array_slice($arr['que_results'], $start, $limit);
        $str = json_encode($arr);
        echo "({$str})";
    } catch (RODSException $e) {
        //echo ($e);
        //echo $e->showStackTrace();
        $arr = array();
        $arr['success'] = false;
        $arr['errmsg'] = $e->getCodeAbbr() . ":" . $e->getMessage();
        $arr['errcode'] = $e->getCode();
        $str = json_encode($arr);
        echo "({$str})";
        exit(0);
    }
}
开发者ID:hussamnasir,项目名称:irods-php,代码行数:60,代码来源:dir_grid.php


示例5: bootstrap_file_widget

/**
 * Overrides theme_file_widget().
 */
function bootstrap_file_widget($variables)
{
    $element = $variables['element'];
    $output = '';
    $hidden_elements = array();
    foreach (element_children($element) as $child) {
        if (isset($element[$child]['#type']) && $element[$child]['#type'] === 'hidden') {
            $hidden_elements[$child] = $element[$child];
            unset($element[$child]);
        }
    }
    $element['upload_button']['#prefix'] = '<span class="input-group-btn">';
    $element['upload_button']['#suffix'] = '</span>';
    // The "form-managed-file" class is required for proper Ajax functionality.
    if (!empty($element['filename'])) {
        $output .= '<div class="file-widget form-managed-file clearfix">';
        // Add the file size after the file name.
        $element['filename']['#markup'] .= ' <span class="file-size badge">' . format_size($element['#file']->filesize) . '</span>';
    } else {
        $output .= '<div class="file-widget form-managed-file clearfix input-group">';
    }
    $output .= drupal_render_children($element);
    $output .= '</div>';
    $output .= render($hidden_elements);
    return $output;
}
开发者ID:victor-galguera,项目名称:Mexico-Nueva-Era,代码行数:29,代码来源:file-widget.func.php


示例6: viewElements

 /**
  * {@inheritdoc}
  */
 public function viewElements(FieldItemListInterface $items)
 {
     $elements = [];
     foreach ($items as $delta => $item) {
         $elements[$delta] = ['#markup' => format_size($item->value)];
     }
     return $elements;
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:11,代码来源:FileSize.php


示例7: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $form = array();
     $bam = backup_migrate_get_service_object();
     $form['backup_migrate_restore_upload'] = array('#title' => t('Upload a Backup File'), '#type' => 'file', '#description' => t("Upload a backup file created by Backup and Migrate. For other database or file backups please use another tool for import. Max file size: %size", array("%size" => format_size(file_upload_max_size()))));
     $form['source_id'] = DrupalConfigHelper::getPluginSelector($bam->sources(), $this->t('Restore To'));
     $conf_schema = $bam->plugins()->map('configSchema', array('operation' => 'restore'));
     $form += DrupalConfigHelper::buildFormFromSchema($conf_schema, $bam->plugins()->config());
     $form['quickbackup']['submit'] = array('#type' => 'submit', '#value' => t('Restore now'), '#weight' => 1);
     return $form;
 }
开发者ID:r-daneelolivaw,项目名称:chalk,代码行数:14,代码来源:BackupMigrateRestoreForm.php


示例8: GetDirectorySize

function GetDirectorySize($path)
{
    $bytestotal = 0;
    $path = realpath($path);
    if ($path !== false) {
        foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS)) as $object) {
            $bytestotal += $object->getSize();
        }
    }
    return format_size($bytestotal);
}
开发者ID:jerien,项目名称:phpsync,代码行数:11,代码来源:agent.php


示例9: listDestinationBackups

 /**
  * List the backups in the given destination.
  *
  * @param \BackupMigrate\Core\Destination\ListableDestinationInterface $destination
  * @return mixed
  */
 public function listDestinationBackups(ListableDestinationInterface $destination, $backup_migrate_destination_id)
 {
     $backups = $destination->listFiles();
     $rows = [];
     $header = array(array('data' => $this->t('Name'), 'class' => array(RESPONSIVE_PRIORITY_MEDIUM)), array('data' => $this->t('Date'), 'class' => array(RESPONSIVE_PRIORITY_MEDIUM)), array('data' => $this->t('Size'), 'class' => array(RESPONSIVE_PRIORITY_MEDIUM)), array('data' => $this->t('Operations'), 'class' => array(RESPONSIVE_PRIORITY_LOW)));
     foreach ($backups as $backup_id => $backup) {
         $rows[] = ['data' => [$backup->getFullName(), \Drupal::service('date.formatter')->format($backup->getMeta('datestamp')), format_size($backup->getMeta('filesize')), ['data' => ['#type' => 'operations', '#links' => ['restore' => ['title' => $this->t('Restore'), 'url' => Url::fromRoute('entity.backup_migrate_destination.backup_restore', ['backup_migrate_destination' => $backup_migrate_destination_id, 'backup_id' => $backup_id])], 'download' => ['title' => $this->t('Download'), 'url' => Url::fromRoute('entity.backup_migrate_destination.backup_download', ['backup_migrate_destination' => $backup_migrate_destination_id, 'backup_id' => $backup_id])], 'delete' => ['title' => $this->t('Delete'), 'url' => Url::fromRoute('entity.backup_migrate_destination.backup_delete', ['backup_migrate_destination' => $backup_migrate_destination_id, 'backup_id' => $backup_id])]]]]]];
     }
     $build['backups_table'] = array('#type' => 'table', '#header' => $header, '#rows' => $rows, '#empty' => $this->t('There are no backups in this destination.'));
     return $build;
 }
开发者ID:r-daneelolivaw,项目名称:chalk,代码行数:17,代码来源:BackupController.php


示例10: instanceSettingsForm

 /**
  * {@inheritdoc}
  */
 public function instanceSettingsForm(array $form, FormStateInterface $form_state)
 {
     $element = array();
     $settings = $this->getSettings();
     $element['file_directory'] = array('#type' => 'textfield', '#title' => t('File directory'), '#default_value' => $settings['file_directory'], '#description' => t('Optional subdirectory within the upload destination where files will be stored. Do not include preceding or trailing slashes.'), '#element_validate' => array(array(get_class($this), 'validateDirectory')), '#weight' => 3);
     // Make the extension list a little more human-friendly by comma-separation.
     $extensions = str_replace(' ', ', ', $settings['file_extensions']);
     $element['file_extensions'] = array('#type' => 'textfield', '#title' => t('Allowed file extensions'), '#default_value' => $extensions, '#description' => t('Separate extensions with a space or comma and do not include the leading dot.'), '#element_validate' => array(array(get_class($this), 'validateExtensions')), '#weight' => 1, '#maxlength' => 256, '#required' => TRUE);
     $element['max_filesize'] = array('#type' => 'textfield', '#title' => t('Maximum upload size'), '#default_value' => $settings['max_filesize'], '#description' => t('Enter a value like "512" (bytes), "80 KB" (kilobytes) or "50 MB" (megabytes) in order to restrict the allowed file size. If left empty the file sizes will be limited only by PHP\'s maximum post and file upload sizes (current limit <strong>%limit</strong>).', array('%limit' => format_size(file_upload_max_size()))), '#size' => 10, '#element_validate' => array(array(get_class($this), 'validateMaxFilesize')), '#weight' => 5);
     $element['description_field'] = array('#type' => 'checkbox', '#title' => t('Enable <em>Description</em> field'), '#default_value' => isset($settings['description_field']) ? $settings['description_field'] : '', '#description' => t('The description field allows users to enter a description about the uploaded file.'), '#parents' => array('instance', 'settings', 'description_field'), '#weight' => 11);
     return $element;
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:15,代码来源:FileItem.php


示例11: preprocessElement

 /**
  * {@inheritdoc}
  */
 public function preprocessElement(Variables $variables, $hook, array $info)
 {
     $variables->addClass(['image-widget', 'js-form-managed-file', 'form-managed-file', 'clearfix']);
     /** @var \Drupal\file\Entity\File $file */
     foreach ($variables->element->getProperty('files') as $file) {
         $variables->element->{'file_' . $file->id()}->filename->setProperty('suffix', ' <span class="file-size badge">' . format_size($file->getSize()) . '</span>');
     }
     $data =& $variables->offsetGet('data', []);
     foreach ($variables->element->children() as $key => $child) {
         $data[$key] = $child->getArray();
     }
 }
开发者ID:slovak-drupal-association,项目名称:komunita.drupal.sk,代码行数:15,代码来源:ImageWidget.php


示例12: fileInfo

function fileInfo($sFile)
{
    $aRtr = array();
    $aRtr["type"] = filetype($sFile);
    $nx_tmp = split("\\/", $sFile);
    $sFileName = array_pop($nx_tmp);
    if ($aRtr["type"] == "file") {
        $aRtr["time"] = filemtime($sFile);
        $aRtr["date"] = date(FILETIME, $aRtr["time"]);
        $aRtr["size"] = filesize($sFile);
        $nx_tmp2 = split("\\.", $sFile);
        $aRtr["mime"] = array_pop($nx_tmp2);
        //mime_content_type($sFile);
        //
        $aRtr["width"] = 0;
        $aRtr["height"] = 0;
        $aImgNfo = $aRtr["mime"] == "jpeg" || $aRtr["mime"] == "jpg" || $aRtr["mime"] == "gif" ? getimagesize($sFile) : "";
        if (is_array($aImgNfo)) {
            list($width, $height, $type, $attr) = $aImgNfo;
            $aRtr["width"] = $width;
            $aRtr["height"] = $height;
        }
        $sNfo = '"file":"' . $sFileName . '",';
        $sNfo .= '"mime":"' . $aRtr["mime"] . '",';
        $sNfo .= '"rsize":' . $aRtr["size"] . ',';
        $sNfo .= '"size":"' . format_size($aRtr["size"]) . '",';
        $sNfo .= '"time":' . $aRtr["time"] . ',';
        $sNfo .= '"date":"' . $aRtr["date"] . '",';
        $sNfo .= '"width":' . $aRtr["width"] . ',';
        $sNfo .= '"height":' . $aRtr["height"];
        $aRtr["stringdata"] = $sNfo;
    } else {
        if ($aRtr["type"] == "dir" && $sFileName != "." && $sFileName != ".." && !preg_match("/^\\./", $sFileName)) {
            $aRtr["mime"] = "folder";
            $aRtr["time"] = filemtime($sFile);
            $aRtr["date"] = date(FILETIME, $aRtr["time"]);
            $aRtr["size"] = filesize($sFile);
            $sNfo = '"file":"' . $sFileName . '",';
            $sNfo .= '"mime":"' . 'folder",';
            $sNfo .= '"rsize":' . '0,';
            $sNfo .= '"size":"' . '-",';
            $sNfo .= '"time":' . $aRtr["time"] . ',';
            $sNfo .= '"date":"' . $aRtr["date"] . '"';
            $aRtr["stringdata"] = $sNfo;
        }
    }
    $aDeny = explode(",", SFB_DENY);
    if (!isset($aRtr["mime"]) || in_array($aRtr["mime"], $aDeny)) {
        return null;
    }
    return $aRtr;
}
开发者ID:elgodmaster,项目名称:soccer2,代码行数:52,代码来源:functions.php


示例13: settingsForm

 /**
  * {@inheritdoc}
  */
 public function settingsForm(array $form, FormStateInterface $form_state)
 {
     $element = parent::settingsForm($form, $form_state);
     $settings = $this->getSettings();
     $element['file_directory'] = array('#type' => 'textfield', '#title' => t('File directory'), '#default_value' => $settings['file_directory'], '#description' => t('Optional subdirectory within the upload destination where files will be stored. Do not include preceding or trailing slashes.'), '#element_validate' => array(array(get_class($this), 'validateDirectory')), '#weight' => 3);
     // Make the extension list a little more human-friendly by comma-separation.
     $extensions = str_replace(' ', ', ', $settings['file_extensions']);
     $element['file_extensions'] = array('#type' => 'textfield', '#title' => t('Allowed file extensions'), '#default_value' => $extensions, '#description' => t('Separate extensions with a space or comma and do not include the leading dot.'), '#element_validate' => array(array(get_class($this), 'validateExtensions')), '#weight' => 1, '#maxlength' => 256, '#required' => TRUE);
     $element['max_filesize'] = array('#type' => 'textfield', '#title' => t('Maximum upload size'), '#default_value' => $settings['max_filesize'], '#description' => t('Enter a value like "512" (bytes), "80 KB" (kilobytes) or "50 MB" (megabytes) in order to restrict the allowed file size. If left empty the file sizes will be limited only by PHP\'s maximum post and file upload sizes (current limit <strong>%limit</strong>).', array('%limit' => format_size(file_upload_max_size()))), '#size' => 10, '#element_validate' => array(array(get_class($this), 'validateMaxFilesize')), '#weight' => 5);
     $scheme_options = \Drupal::service('stream_wrapper_manager')->getNames(StreamWrapperInterface::WRITE_VISIBLE);
     $element['uri_scheme'] = array('#type' => 'radios', '#title' => t('Upload destination'), '#options' => $scheme_options, '#default_value' => $this->getSetting('uri_scheme'), '#description' => t('Select where the final files should be stored. Private file storage has significantly more overhead than public files, but allows restricted access to files within this field.'), '#weight' => 6);
     return $element;
 }
开发者ID:kallehauge,项目名称:iamkallehauge.com,代码行数:16,代码来源:VideoUploadWidget.php


示例14: _buildRuntimeFile

 /**
  * 创建运行时文件
  *
  * @author          mrmsl <[email protected]>
  * @date            2013-01-22 15:45:33
  * @lastmodify      2013-02-18 17:03:00 by mrmsl
  *
  * @return void 无返回值
  */
 private function _buildRuntimeFile()
 {
     $filesize = 0;
     //加载文件大小
     $compile = "<?php\n!defined('YAB_PATH') && exit('Access Denied');";
     //编译内容
     //加载核心文件
     foreach ($this->_require_files as $file) {
         require $file;
         if (defined('APP_DEBUG') && !APP_DEBUG) {
             $filesize += filesize($file);
             $compile .= compile_file($file);
         }
     }
     $require_files = array(CORE_PATH . 'Bootstrap.' . APP_EXT, CORE_PATH . 'Template.' . APP_EXT, CORE_PATH . 'Model.' . APP_EXT, CORE_PATH . 'Logger.' . APP_EXT, CORE_PATH . 'Filter.' . APP_EXT, CORE_PATH . 'Db.' . APP_EXT, CORE_PATH . 'drivers/db/Db' . ucfirst(DB_TYPE) . '.' . APP_EXT);
     if (is_file($filename = LIB_PATH . 'BaseController.' . APP_EXT)) {
         //底层控制器类
         $require_files[] = $filename;
     }
     if (is_file($filename = APP_PATH . 'controllers/Common.' . APP_EXT)) {
         //项目底层通用控制器类
         $require_files[] = $filename;
     }
     if (is_file($filename = LIB_PATH . 'BaseModel.' . APP_EXT)) {
         //底层模型类
         $require_files[] = $filename;
     }
     if (is_file($filename = APP_PATH . 'models/Common.' . APP_EXT)) {
         //项目底层通用模型类
         $require_files[] = $filename;
     }
     //加载核心文件,用空间换时间
     if (APP_DEBUG) {
         //调试
         foreach ($require_files as $file) {
             require $file;
         }
     } else {
         foreach ($require_files as $file) {
             require $file;
             $filesize += filesize($file);
             $compile .= compile_file($file);
         }
         file_put_contents(RUNTIME_FILE, $compile);
         $size = filesize(RUNTIME_FILE);
         //编译后大小
         file_put_contents(LOG_PATH . 'compile_runtime_file.log', new_date() . '(' . format_size($filesize) . ' => ' . format_size($size) . ')' . EOL_LF, FILE_APPEND);
     }
 }
开发者ID:yunsite,项目名称:yablog,代码行数:58,代码来源:Yablog.class.php


示例15: testFileTokenReplacement

 /**
  * Creates a file, then tests the tokens generated from it.
  */
 function testFileTokenReplacement()
 {
     $node_storage = $this->container->get('entity.manager')->getStorage('node');
     $token_service = \Drupal::token();
     $language_interface = \Drupal::languageManager()->getCurrentLanguage();
     // Create file field.
     $type_name = 'article';
     $field_name = 'field_' . strtolower($this->randomMachineName());
     $this->createFileField($field_name, 'node', $type_name);
     $test_file = $this->getTestFile('text');
     // Coping a file to test uploads with non-latin filenames.
     $filename = drupal_dirname($test_file->getFileUri()) . '/текстовый файл.txt';
     $test_file = file_copy($test_file, $filename);
     // Create a new node with the uploaded file.
     $nid = $this->uploadNodeFile($test_file, $field_name, $type_name);
     // Load the node and the file.
     $node_storage->resetCache(array($nid));
     $node = $node_storage->load($nid);
     $file = file_load($node->{$field_name}->target_id);
     // Generate and test sanitized tokens.
     $tests = array();
     $tests['[file:fid]'] = $file->id();
     $tests['[file:name]'] = String::checkPlain($file->getFilename());
     $tests['[file:path]'] = String::checkPlain($file->getFileUri());
     $tests['[file:mime]'] = String::checkPlain($file->getMimeType());
     $tests['[file:size]'] = format_size($file->getSize());
     $tests['[file:url]'] = String::checkPlain(file_create_url($file->getFileUri()));
     $tests['[file:created]'] = format_date($file->getCreatedTime(), 'medium', '', NULL, $language_interface->getId());
     $tests['[file:created:short]'] = format_date($file->getCreatedTime(), 'short', '', NULL, $language_interface->getId());
     $tests['[file:changed]'] = format_date($file->getChangedTime(), 'medium', '', NULL, $language_interface->getId());
     $tests['[file:changed:short]'] = format_date($file->getChangedTime(), 'short', '', NULL, $language_interface->getId());
     $tests['[file:owner]'] = String::checkPlain(user_format_name($this->adminUser));
     $tests['[file:owner:uid]'] = $file->getOwnerId();
     // Test to make sure that we generated something for each token.
     $this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.');
     foreach ($tests as $input => $expected) {
         $output = $token_service->replace($input, array('file' => $file), array('langcode' => $language_interface->getId()));
         $this->assertEqual($output, $expected, format_string('Sanitized file token %token replaced.', array('%token' => $input)));
     }
     // Generate and test unsanitized tokens.
     $tests['[file:name]'] = $file->getFilename();
     $tests['[file:path]'] = $file->getFileUri();
     $tests['[file:mime]'] = $file->getMimeType();
     $tests['[file:size]'] = format_size($file->getSize());
     foreach ($tests as $input => $expected) {
         $output = $token_service->replace($input, array('file' => $file), array('langcode' => $language_interface->getId(), 'sanitize' => FALSE));
         $this->assertEqual($output, $expected, format_string('Unsanitized file token %token replaced.', array('%token' => $input)));
     }
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:52,代码来源:FileTokenReplaceTest.php


示例16: render

 /**
  * {@inheritdoc}
  */
 public function render(ResultRow $values)
 {
     $value = $this->getValue($values);
     if ($value) {
         switch ($this->options['file_size_display']) {
             case 'bytes':
                 return $value;
             case 'formatted':
             default:
                 return format_size($value);
         }
     } else {
         return '';
     }
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:18,代码来源:FileSize.php


示例17: form

 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $imce_profile = $this->getEntity();
     // Check duplication
     if ($this->getOperation() === 'duplicate') {
         $imce_profile = $imce_profile->createDuplicate();
         $imce_profile->set('label', $this->t('Duplicate of @label', array('@label' => $imce_profile->label())));
         $this->setEntity($imce_profile);
     }
     // Label
     $form['label'] = array('#type' => 'textfield', '#title' => $this->t('Name'), '#default_value' => $imce_profile->label(), '#maxlength' => 64, '#required' => TRUE, '#weight' => -20);
     // Id
     $form['id'] = array('#type' => 'machine_name', '#machine_name' => array('exists' => array(get_class($imce_profile), 'load'), 'source' => array('label')), '#default_value' => $imce_profile->id(), '#maxlength' => 32, '#required' => TRUE, '#weight' => -20);
     // Description
     $form['description'] = array('#type' => 'textfield', '#title' => $this->t('Description'), '#default_value' => $imce_profile->get('description'), '#weight' => -10);
     // Conf
     $conf = array('#tree' => TRUE);
     // Extensions
     $conf['extensions'] = array('#type' => 'textfield', '#title' => $this->t('Allowed file extensions'), '#default_value' => $imce_profile->getConf('extensions'), '#maxlength' => 255, '#description' => $this->t('Separate extensions with a space or comma and do not include the leading dot.') . ' ' . $this->t('Set to * to allow all extensions.'), '#weight' => -9);
     // File size
     $maxsize = file_upload_max_size();
     $conf['maxsize'] = array('#type' => 'number', '#min' => 0, '#max' => ceil($maxsize / 1024 / 1024), '#step' => 'any', '#size' => 8, '#title' => $this->t('Maximum file size'), '#default_value' => $imce_profile->getConf('maxsize'), '#description' => $this->t('Maximum allowed file size per upload.') . ' ' . t('Your PHP settings limit the upload size to %size.', array('%size' => format_size($maxsize))), '#field_suffix' => $this->t('MB'), '#weight' => -8);
     // Quota
     $conf['quota'] = array('#type' => 'number', '#min' => 0, '#step' => 'any', '#size' => 8, '#title' => $this->t('Disk quota'), '#default_value' => $imce_profile->getConf('quota'), '#description' => $this->t('Maximum disk space that can be allocated by a user.'), '#field_suffix' => $this->t('MB'), '#weight' => -7);
     // Image dimensions
     $conf['dimensions'] = array('#type' => 'container', '#attributes' => array('class' => array('dimensions-wrapper form-item')), '#weight' => -6);
     $conf['dimensions']['label'] = array('#markup' => '<label>' . $this->t('Maximum image dimensions') . '</label>');
     $conf['dimensions']['maxwidth'] = array('#type' => 'number', '#default_value' => $imce_profile->getConf('maxwidth'), '#maxlength' => 5, '#min' => 0, '#size' => 8, '#placeholder' => $this->t('Width'), '#field_suffix' => ' x ', '#parents' => array('conf', 'maxwidth'));
     $conf['dimensions']['maxheight'] = array('#type' => 'number', '#default_value' => $imce_profile->getConf('maxheight'), '#maxlength' => 5, '#min' => 0, '#size' => 8, '#placeholder' => $this->t('Height'), '#field_suffix' => $this->t('pixels'), '#parents' => array('conf', 'maxheight'));
     $conf['dimensions']['description'] = array('#markup' => '<div class="description">' . $this->t('Images exceeding the limit will be scaled down.') . '</div>');
     // Replace method
     $conf['replace'] = array('#type' => 'radios', '#title' => $this->t('Upload replace method'), '#default_value' => $imce_profile->getConf('replace', FILE_EXISTS_RENAME), '#options' => array(FILE_EXISTS_RENAME => t('Keep the existing file renaming the new one'), FILE_EXISTS_REPLACE => t('Replace the existing file with the new one'), FILE_EXISTS_ERROR => t('Keep the existing file rejecting the new one')), '#description' => $this->t('Select the replace method for existing files during uploads.'), '#weight' => -5);
     // Folders
     $conf['folders'] = array('#type' => 'fieldset', '#title' => $this->t('Folders'), 'description' => array('#markup' => '<div class="description">' . $this->t('You can use user tokens in folder paths, e.g. @tokens.', array('@tokens' => '[user:uid], [user:name]')) . ' ' . $this->t('Subfolders inherit parent permissions when subfolder browsing is enabled.') . '</div>'), '#weight' => 10);
     $folders = $imce_profile->getConf('folders', array());
     $index = 0;
     foreach ($folders as $folder) {
         $conf['folders'][] = $this->folderForm($index++, $folder);
     }
     $conf['folders'][] = $this->folderForm($index++);
     $conf['folders'][] = $this->folderForm($index);
     $form['conf'] = $conf;
     // Add library
     $form['#attached']['library'][] = 'imce/drupal.imce.admin';
     // Call plugin form alterers
     \Drupal::service('plugin.manager.imce.plugin')->alterProfileForm($form, $form_state, $imce_profile);
     return parent::form($form, $form_state);
 }
开发者ID:Progressable,项目名称:openway8,代码行数:51,代码来源:ImceProfileForm.php


示例18: viewElements

 /**
  * {@inheritdoc}
  */
 public function viewElements(FieldItemListInterface $items)
 {
     $elements = array();
     if ($files = $this->getEntitiesToView($items)) {
         $header = array(t('Attachment'), t('Size'));
         $rows = array();
         foreach ($files as $delta => $file) {
             $rows[] = array(array('data' => array('#theme' => 'file_link', '#file' => $file, '#cache' => array('tags' => $file->getCacheTags()))), array('data' => format_size($file->getSize())));
         }
         $elements[0] = array();
         if (!empty($rows)) {
             $elements[0] = array('#theme' => 'table__file_formatter_table', '#header' => $header, '#rows' => $rows);
         }
     }
     return $elements;
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:19,代码来源:TableFormatter.php


示例19: bootstrap_preprocess_file_widget

/**
 * Overrides theme_file_widget().
 */
function bootstrap_preprocess_file_widget(&$variables)
{
    $element = $variables['element'];
    if (!empty($element['fids']['#value'])) {
        // Add the file size after the file name.
        $file = reset($element['#files']);
        $element['file_' . $file->id()]['filename']['#suffix'] = ' <span class="file-size badge">' . format_size($file->getSize()) . '</span> ';
    }
    // The "form-managed-file" class is required for proper Ajax functionality.
    $variables['attributes'] = array('class' => array('file-widget', 'form-managed-file', 'clearfix'));
    $element['upload']['#prefix'] = '<div class="input-group">';
    $element['upload_button']['#prefix'] = '<span class="input-group-btn">';
    $element['upload_button']['#suffix'] = '</span></div>';
    $element['upload_button']['#attributes']['class'] = array('btn', 'btn-primary');
    $variables['element'] = $element;
}
开发者ID:sathishRio,项目名称:themes,代码行数:19,代码来源:file-widget.vars.php


示例20: display

 function display()
 {
     current_page('files');
     page_title(lang('fl_mylist'), URL . '/files/');
     if (!user('logged')) {
         return login_req();
     }
     $data = ldb_select('upload', '*', '`uid`=' . user('id') . ' ORDER BY `tms_upload` DESC');
     $u_list = '';
     for ($x = 0; $x < count($data); $x++) {
         $f_title = '';
         if ($data[$x]['comment']) {
             $f_title = htmlspecialchars($data[$x]['comment']);
         } else {
             # Get files
             $f_list = ldb_select('file', array('file_name'), '`upid`=' . $data[$x]['id'] . ' ORDER BY `id`');
             $f_list_len = 0;
             $f_list_d = array();
             for ($a = 0; $a < count($f_list); $a++) {
                 $f_list_d[] = '<i>' . htmlspecialchars($f_list[$a]['file_name']) . '</i>';
                 $f_list_len += mb_strlen($f_list[$a]['file_name'], 'UTF-8');
                 if ($f_list_len > 50) {
                     break;
                 }
             }
             if (count($f_list_d) < count($f_list)) {
                 $f_list_d[] = '<b>...</b>';
             }
             $f_title = implode(', ', $f_list_d);
         }
         $f_title = trim($f_title);
         if (!$f_title) {
             $f_title = sprintf(lang('fld_title_n'), $data[$x]['id']);
         }
         $u_list .= '<tr>';
         $u_list .= '<td align="center">' . $data[$x]['id'] . '</td>';
         $u_list .= '<td align="left" class="mf-table-flink"><a href="' . URL . '/f/' . $data[$x]['code'] . '/">' . $f_title . '</a></td>';
         $u_list .= '<td align="center">' . date('d.m.Y H:i', $data[$x]['tms_upload']) . '</td>';
         $u_list .= '<td align="center">' . time_delete($data[$x]['tms_upload'], $data[$x]['tms_delete']) . '</td>';
         $u_list .= '<td align="center">' . format_size($data[$x]['file_size']) . '</td>';
         $u_list .= '</tr>';
     }
     $tpl = new ltpl('myfiles');
     $tpl->v('u_list', $u_list);
     return $tpl->get();
 }
开发者ID:petrows,项目名称:Upload-service,代码行数:46,代码来源:mod_files.php



注:本文中的format_size函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP format_str函数代码示例发布时间:2022-05-15
下一篇:
PHP format_si函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap