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


PHP CakeNumber::fromReadableSize方法代码示例

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


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

示例1: startup

 /**
  * Called after the Controller::beforeFilter() and before the controller action
  *
  * @param Controller $controller Controller with components to startup
  * @return void
  */
 public function startup(Controller $controller)
 {
     // ファイルアップロード等で post_max_size を超えると $_POSTが空っぽになるため、このタイミングでエラー表示
     $contentLength = Hash::get($_SERVER, 'CONTENT_LENGTH');
     if ($contentLength > CakeNumber::fromReadableSize(ini_get('post_max_size'))) {
         $message = __d('files', 'FileUpload.post_max_size.over');
         $controller->NetCommons->setFlashNotification($message, array('class' => 'danger', 'interval' => NetCommonsComponent::ALERT_VALIDATE_ERROR_INTERVAL));
         $controller->redirect($controller->referer());
     }
 }
开发者ID:s-nakajima,项目名称:files,代码行数:16,代码来源:FileUploadComponent.php

示例2: addMedia

 /**
  * Add media file
  *
  * @param array $requestData Array of POST data. Will contain form data as well as uploaded files.
  *
  * @return bool
  * @throws CakeException
  */
 public function addMedia(array $requestData)
 {
     if (CakeNumber::fromReadableSize(ini_get('post_max_size')) < env('CONTENT_LENGTH')) {
         throw new CakeException(__d('hurad', 'File could not be uploaded. please increase "post_max_size" in php.ini'));
     }
     $this->set($requestData);
     if ($this->validates()) {
         $prefix = uniqid() . '_';
         $uploadInfo = $requestData['Media']['media_file'];
         $path = date('Y') . DS . date('m');
         if ($uploadInfo['error']) {
             throw new CakeException($this->getUploadErrorMessages($uploadInfo['error']));
         }
         $folder = new Folder(WWW_ROOT . 'files' . DS . $path, true, 0755);
         if (!is_writable(WWW_ROOT . 'files')) {
             throw new CakeException(__d('hurad', '%s is not writable', WWW_ROOT . 'files'));
         }
         if (!move_uploaded_file($uploadInfo['tmp_name'], $folder->pwd() . DS . $prefix . $uploadInfo['name'])) {
             throw new CakeException(__d('hurad', 'File could not be uploaded. Please, try again.'));
         }
         $file = new File($folder->pwd() . DS . $prefix . $uploadInfo['name']);
         $requestData['Media']['user_id'] = CakeSession::read('Auth.User.id');
         $requestData['Media']['name'] = $prefix . $uploadInfo['name'];
         $requestData['Media']['original_name'] = $uploadInfo['name'];
         $requestData['Media']['mime_type'] = $file->mime();
         $requestData['Media']['size'] = $file->size();
         $requestData['Media']['extension'] = $file->ext();
         $requestData['Media']['path'] = $path;
         $requestData['Media']['web_path'] = Configure::read('General.site_url') . '/' . 'files' . '/' . $path . '/' . $prefix . $uploadInfo['name'];
         $this->create();
         if ($this->save($requestData)) {
             return true;
         } else {
             return false;
         }
     } else {
         return false;
     }
 }
开发者ID:hurad,项目名称:hurad,代码行数:47,代码来源:Media.php

示例3: __construct

 /**
  * Sets protected properties based on config provided
  *
  * @param array $config Configuration array
  */
 public function __construct(array $config = [])
 {
     parent::__construct($config);
     if (!empty($this->_config['path'])) {
         $this->_path = $this->_config['path'];
     }
     if (Configure::read('debug') && !is_dir($this->_path)) {
         mkdir($this->_path, 0775, true);
     }
     if (!empty($this->_config['file'])) {
         $this->_file = $this->_config['file'];
         if (substr($this->_file, -4) !== '.log') {
             $this->_file .= '.log';
         }
     }
     if (!empty($this->_config['size'])) {
         if (is_numeric($this->_config['size'])) {
             $this->_size = (int) $this->_config['size'];
         } else {
             $this->_size = CakeNumber::fromReadableSize($this->_config['size']);
         }
     }
 }
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:28,代码来源:FileLog.php

示例4: fileSize

 /**
  * Checks the filesize
  *
  * @param string|array $check
  * @param integer|string $size Size in bytes or human readable string like '5MB'
  * @param string $operator See `Validation::comparison()`
  * @return boolean Success
  */
 public static function fileSize($check, $operator = null, $size = null)
 {
     if (is_array($check) && isset($check['tmp_name'])) {
         $check = $check['tmp_name'];
     }
     if (is_string($size)) {
         $size = CakeNumber::fromReadableSize($size);
     }
     $filesize = filesize($check);
     return self::comparison($filesize, $operator, $size);
 }
开发者ID:byu-oit-appdev,项目名称:student-ratings,代码行数:19,代码来源:Validation.php

示例5: config

 /**
  * Sets protected properties based on config provided
  *
  * @param array $config Engine configuration
  *
  * @return array
  */
 public function config($config = array())
 {
     parent::config($config);
     if (!empty($config['path'])) {
         $this->_path = $config['path'];
     }
     if (Configure::read('debug') && !is_dir($this->_path)) {
         mkdir($this->_path, 0775, TRUE);
     }
     if (!empty($config['file'])) {
         $this->_file = $config['file'];
         if (substr($this->_file, -4) !== '.log') {
             $this->_file .= '.log';
         }
     }
     if (!empty($config['size'])) {
         if (is_numeric($config['size'])) {
             $this->_size = (int) $config['size'];
         } else {
             $this->_size = CakeNumber::fromReadableSize($config['size']);
         }
     }
     return $this->_config;
 }
开发者ID:mrbadao,项目名称:api-official,代码行数:31,代码来源:FileLog.php

示例6: beforeValidate

 /**
  * Called during validation operations, before validation. Please note that custom
  * validation rules can be defined in $validate.
  *
  * @param array $options Options passed from Model::save().
  * @return bool True if validate operation should continue, false to abort
  * @link http://book.cakephp.org/2.0/en/models/callback-methods.html#beforevalidate
  * @see Model::save()
  */
 public function beforeValidate($options = array())
 {
     $postMaxSize = CakeNumber::fromReadableSize(ini_get('post_max_size'));
     $uploadMaxFilesize = CakeNumber::fromReadableSize(ini_get('upload_max_filesize'));
     $maxUploadSize = CakeNumber::toReadableSize($postMaxSize > $uploadMaxFilesize ? $uploadMaxFilesize : $postMaxSize);
     $this->validate = Hash::merge($this->validate, array(self::INPUT_NAME => array('uploadError' => array('rule' => array('uploadError'), 'message' => array('Error uploading file'))), 'name' => array('notBlank' => array('rule' => array('notBlank'), 'message' => __d('net_commons', 'Invalid request.'), 'allowEmpty' => false, 'required' => true)), 'slug' => array('notBlank' => array('rule' => array('notBlank'), 'message' => __d('net_commons', 'Invalid request.'), 'allowEmpty' => false, 'required' => true)), 'path' => array('notBlank' => array('rule' => array('notBlank'), 'message' => __d('net_commons', 'Invalid request.'), 'allowEmpty' => false, 'on' => 'create')), 'extension' => array('notBlank' => array('rule' => array('notBlank'), 'message' => __d('net_commons', 'Invalid request.'), 'allowEmpty' => false, 'required' => true)), 'mimetype' => array('notBlank' => array('rule' => array('notBlank'), 'message' => __d('net_commons', 'Invalid request.'), 'allowEmpty' => false)), 'size' => array('numeric' => array('rule' => array('numeric'), 'message' => __d('net_commons', 'Invalid request.'), 'allowEmpty' => false)), 'role_type' => array('notBlank' => array('rule' => array('notBlank'), 'message' => __d('net_commons', 'Invalid request.'), 'allowEmpty' => false, 'required' => true)), 'number_of_downloads' => array('numeric' => array('rule' => array('numeric'), 'message' => __d('net_commons', 'Invalid request.'))), 'status' => array('numeric' => array('rule' => array('numeric'), 'message' => __d('net_commons', 'Invalid request.')))));
     return parent::beforeValidate($options);
 }
开发者ID:s-nakajima,项目名称:FileDevs,代码行数:17,代码来源:FileModel_bk.php

示例7: add2

 /**
  * edit method
  *
  * @return void
  */
 public function add2()
 {
     if ($this->request->isPost()) {
         //			$data = $this->data;
         //			if (isset($data['File'][self::INPUT_NAME])) {
         //				$data['File']['name'] = $data['File'][self::INPUT_NAME]['name'];
         //				$data['File']['slug'] = Security::hash($data['File']['name'] . mt_rand() . microtime(), 'md5');
         //				$data['File']['extension'] = pathinfo($data['File']['name'], PATHINFO_EXTENSION);
         //				$data['File']['original_name'] = $data['File']['slug'];
         //
         //				if (preg_match('/^image/', $data['File'][self::INPUT_NAME]['type']) === 1 ||
         //						preg_match('/^video/', $data['File'][self::INPUT_NAME]['type']) === 1) {
         //					$data['File']['alt'] = $data['File']['name'];
         //				}
         //				$this->FileModel->setUploadPath(self::INPUT_NAME, $data);
         //			}
         //
         //			if (! $result = $this->FileModel->saveFile($data)) {
         //				//TODO: Error
         //				return;
         //			}
         //			$result[$this->FileModel->alias]['readableSize'] =
         //					CakeNumber::toReadableSize($result[$this->FileModel->alias]['size']);
         //
         //			$this->renderJson($result);
     } else {
         $this->layout = null;
         $this->set('tabIndex', 0);
         $postMaxSize = CakeNumber::fromReadableSize(ini_get('post_max_size'));
         $uploadMaxFilesize = CakeNumber::fromReadableSize(ini_get('upload_max_filesize'));
         $this->set('maxUploadSize', CakeNumber::toReadableSize($postMaxSize > $uploadMaxFilesize ? $uploadMaxFilesize : $postMaxSize));
         $this->set('maxDiskSize', CakeNumber::toReadableSize(1073741824));
         $this->set('useDiskSize', CakeNumber::toReadableSize(50000000));
         $this->set('data', ['File' => ['role_type' => $this->params->query['roleType'] ? $this->params->query['roleType'] : ''], 'FilesPlugin' => ['plugin_key' => $this->params->query['pluginKey'] ? $this->params->query['pluginKey'] : ''], 'FilesRoom' => ['room_id' => isset($this->params->query['roomId']) ? (int) $this->params->query['roomId'] : 0], 'FilesUser' => ['user_id' => isset($this->params->query['userId']) ? (int) $this->params->query['userId'] : (int) $this->Auth->user('id')]]);
         $this->set('accept', $this->params->query['accept']);
     }
     return;
 }
开发者ID:s-nakajima,项目名称:FileDevs,代码行数:43,代码来源:FilesController.php


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