当前位置: 首页>>代码示例>>PHP>>正文


PHP waFiles::formatSize方法代码示例

本文整理汇总了PHP中waFiles::formatSize方法的典型用法代码示例。如果您正苦于以下问题:PHP waFiles::formatSize方法的具体用法?PHP waFiles::formatSize怎么用?PHP waFiles::formatSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在waFiles的用法示例。


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

示例1: save

 protected function save(waRequestFile $file)
 {
     if (!$this->model) {
         $this->model = new shopProductSkusModel();
     }
     $field = array('id' => waRequest::post('sku_id', null, waRequest::TYPE_INT), 'product_id' => waRequest::post('product_id', null, waRequest::TYPE_INT));
     $data = array('file_size' => $file->size, 'file_name' => $file->name);
     $this->model->updateByField($field, $data);
     $file_path = shopProduct::getPath($field['product_id'], "sku_file/{$field['id']}." . pathinfo($file->name, PATHINFO_EXTENSION));
     if (file_exists($file_path) && !is_writable($file_path) || !file_exists($file_path) && !waFiles::create($file_path)) {
         $data = array('file_size' => 0, 'file_name' => '');
         $this->model->updateByField($field, $data);
         throw new waException(sprintf("The insufficient file write permissions for the %s folder.", substr($file_path, strlen($this->getConfig()->getRootPath()))));
     }
     $file->moveTo($file_path);
     return array('name' => $file->name, 'size' => waFiles::formatSize($file->size));
 }
开发者ID:Lazary,项目名称:webasyst,代码行数:17,代码来源:shopProductSkuEproductUpload.controller.php

示例2: execute

 public function execute()
 {
     $id = waRequest::get('id', 0, waRequest::TYPE_INT);
     if (!$id) {
         throw new waException("Unknown product");
     }
     $product = new shopProduct($id);
     $sizes = $this->getConfig()->getImageSizes('system');
     $images = $product->getImages($sizes);
     $param = waRequest::get('param', array(), waRequest::TYPE_ARRAY_INT);
     $image_id = !empty($param[0]) ? $param[0] : 0;
     if (isset($images[$image_id])) {
         $image = $images[$image_id];
         if ($image['size']) {
             $image['size'] = waFiles::formatSize($image['size'], '%0.2f', 'B,KB,MB,GB');
         }
         $this->setTemplate('ProductImage');
         $images = array_values($images);
         array_unshift($images, null);
         array_push($images, null);
         $offset = 0;
         foreach ($images as $k => $img) {
             if ($image['id'] == $img['id']) {
                 $offset = $k;
             }
         }
         $next = $images[$offset + 1];
         $image['dimensions'] = shopImage::getThumbDimensions($image, $sizes['big']);
         $this->view->assign(array('image' => $image, 'next' => $next, 'offset' => $offset, 'original_exists' => file_exists(shopImage::getOriginalPath($image)), 'photostream' => waRequest::get('ps', array())));
     }
     $this->view->assign(array('sizes' => $sizes, 'images' => $images, 'count' => count($images) - 2, 'product_id' => $id, 'product' => $product));
     /**
      * @event backend_product_edit
      * @return array[string][string]string $return[%plugin_id%]['images'] html output
      */
     $this->view->assign('backend_product_edit', wa()->event('backend_product_edit', $product));
 }
开发者ID:Lazary,项目名称:webasyst,代码行数:37,代码来源:shopProductImages.action.php

示例3: formatSize

 public static function formatSize($size)
 {
     return waFiles::formatSize($size, '%0.2f', _w('B,KB,MB,GB'));
 }
开发者ID:Lazary,项目名称:webasyst,代码行数:4,代码来源:logsHelper.class.php

示例4: save

 protected function save(waRequestFile $file)
 {
     $path = wa()->getTempPath('csv/upload/');
     waFiles::create($path);
     $original_name = $file->name;
     if ($name = tempnam($path, 'csv')) {
         unlink($name);
         if (($ext = pathinfo($original_name, PATHINFO_EXTENSION)) && preg_match('/^\\w+$/', $ext)) {
             $name .= '.' . $ext;
         }
         $file->moveTo($name);
     } else {
         throw new waException(_w('Error file upload'));
     }
     $encoding = waRequest::post('encoding', 'UTF-8');
     $delimiter = waRequest::post('delimiter');
     try {
         $this->reader = new shopCsvReader($name, $delimiter, $encoding);
         $delimiters = array(';', ',', 'tab');
         $used_delimiters = array($delimiter);
         while (count($this->reader->header()) < 2 && ($delimiter = array_diff($delimiters, $used_delimiters))) {
             $delimiter = reset($delimiter);
             $used_delimiters[] = $delimiter;
             $this->reader->delete();
             $this->reader = new shopCsvReader($name, $delimiter, $encoding);
         }
         if (count($this->reader->header()) < 2) {
             $this->reader->delete();
             $delimiter = waRequest::post('delimiter');
             $this->reader = new shopCsvReader($name, $delimiter, $encoding);
         }
         $encodings = array('UTF-8', 'Windows-1251', 'ISO-8859-1');
         $used_encodings = array($encoding);
         while (in_array(false, (array) $this->reader->header(), true) && ($encoding = array_diff($encodings, $used_encodings))) {
             $encoding = reset($encoding);
             $used_encodings[] = $encoding;
             $this->reader->delete();
             $this->reader = new shopCsvReader($name, $delimiter, $encoding);
         }
         if (in_array(false, (array) $this->reader->header(), true) || count($this->reader->header()) < 2) {
             throw new waException($this->reader->header() ? _w('No data columns were located in the uploaded file. Make sure right separator and encoding were chosen for this upload.') : _w('Unsupported CSV file structure'));
         }
         $profile_helper = new shopImportexportHelper('csv:product:import');
         $profile = $profile_helper->getConfig();
         $profile['config'] += array('encoding' => $encoding, 'delimiter' => ';', 'map' => array());
         $params = array();
         $params['id'] = 'csvproducts';
         $params['title_wrapper'] = '%s';
         $params['description_wrapper'] = '<br><span class="hint">%s</span>';
         $params['control_wrapper'] = '<div class="field"><div class="name">%s</div><div class="value">%s %s</div></div>';
         $params['options'] = $this->options();
         $control = true ? shopCsvReader::TABLE_CONTROL : shopCsvReader::MAP_CONTROL;
         switch ($control) {
             case shopCsvReader::TABLE_CONTROL:
                 $params['preview'] = 50;
                 $params['columns'] = array(array('shopCsvProductviewController', 'tableRowHandler'), '&nbsp;');
                 $params['control_wrapper'] = '<div class="field"><div class="value" style="overflow-x:auto;margin-left:0;">%s %s</div></div>';
                 $params['title_wrapper'] = false;
                 $params['row_handler'] = 'csv_product/rows/';
                 $params['row_handler_string'] = true;
                 $params['autocomplete_handler'] = 'csv_product/autocomplete/reset/';
                 break;
             case shopCsvReader::MAP_CONTROL:
             default:
                 $control = shopCsvReader::MAP_CONTROL;
                 break;
         }
         return array('name' => htmlentities(basename($this->reader->file()), ENT_QUOTES, 'utf-8'), 'original_name' => htmlentities(basename($original_name), ENT_QUOTES, 'utf-8'), 'size' => waFiles::formatSize($this->reader->size()), 'original_size' => waFiles::formatSize($file->size), 'controls' => waHtmlControl::getControl($control, 'csv_map', $params), 'control' => $control, 'header' => $this->reader->header(), 'columns_offset' => count(ifset($params['columns'], array())), 'delimiter' => $delimiter, 'encoding' => $encoding);
     } catch (waException $ex) {
         if ($this->reader) {
             $this->reader->delete(true);
         }
         throw $ex;
     }
 }
开发者ID:Lazary,项目名称:webasyst,代码行数:75,代码来源:shopCsvProductupload.controller.php


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