Example #1
0
 /**
  * Returns a formatted-for-humans file size.
  *
  * @param int $size Size in bytes
  * @return string Human readable size
  * @see \Cake\I18n\Number::toReadableSize()
  * @link http://book.cakephp.org/3.0/en/views/helpers/number.html#interacting-with-human-readable-values
  */
 public function toReadableSize($size)
 {
     return $this->_engine->toReadableSize($size);
 }
Example #2
0
 /**
  * Get the summary for the panel.
  *
  * @return string
  */
 public function summary()
 {
     $time = Number::precision(DebugTimer::requestTime(), 2) . ' s';
     $memory = Number::toReadableSize(DebugMemory::getPeak());
     return "{$time} / {$memory}";
 }
Example #3
0
 /**
  * Returns a formatted-for-humans file size.
  *
  * @param int $size Size in bytes
  * @return string Human readable size
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/number.html#NumberHelper::toReadableSize
  */
 public static function _toReadableSize($size, $decimals = '.')
 {
     $size = parent::toReadableSize($size);
     if ($decimals !== '.') {
         $size = str_replace('.', $decimals, $size);
     }
     return $size;
 }
 /**
  * Lists database backups
  * @return void
  * @uses DatabaseBackup\Utility\Backup::index()
  */
 public function index()
 {
     try {
         //Gets alla files
         $files = Backup::index();
         $this->out(__d('database_backup', 'Backup files found: {0}', count($files)));
         if (!empty($files)) {
             //Re-indexes and filters
             $files = array_map(function ($file) {
                 return [$file->filename, $file->compression, Number::toReadableSize($file->size), $file->datetime];
             }, $files);
             $this->helper('table')->output(array_merge([[__d('database_backup', 'Filename'), __d('database_backup', 'Compression'), __d('database_backup', 'Size'), __d('database_backup', 'Datetime')]], $files));
         }
     } catch (InternalErrorException $e) {
         $this->abort($e->getMessage());
     }
 }
Example #5
0
 /**
  * Save file
  * @param null $order_id
  */
 public function file($order_id = null)
 {
     $file_data = $this->request->data('file');
     $file_name = new File($file_data['name']);
     $name = preg_replace('/\\s+/', '_', $file_name->name()) . '.' . $file_name->ext();
     if (!move_uploaded_file($file_data['tmp_name'], 'files/' . $name)) {
         throw new InternalErrorException(json_encode($file_data));
     }
     $fileObj = $this->Files->newEntity(['name' => $name, 'order_id' => $order_id, 'size' => Number::toReadableSize($file_data['size'])]);
     $file = $this->Files->save($fileObj);
     $this->set('row', $file);
     $this->set('_serialize', ['row']);
 }
 /**
  * Validates the error value that comes with the file input file.
  *
  * @param array $value
  * @param array $options.
  * @return boolean True on success, if false the error message is set to the models field and also set in $this->_uploadError
  */
 public function uploadErrors($value, $options = array())
 {
     $defaults = ['allowNoFileError' => true];
     if (is_array($options)) {
         $options = array_merge($defaults, $options);
     } else {
         $options = $defaults;
     }
     if (isset($value['error']) && !is_null($value['error'])) {
         switch ($value['error']) {
             case UPLOAD_ERR_OK:
                 return true;
             case UPLOAD_ERR_INI_SIZE:
                 $this->_uploadError = __d('file_storage', 'The uploaded file exceeds limit of %s.', Number::toReadableSize(ini_get('upload_max_filesize')));
                 return false;
             case UPLOAD_ERR_FORM_SIZE:
                 $this->_uploadError = __d('file_storage', 'The uploaded file is to big, please choose a smaller file or try to compress it.');
                 return false;
             case UPLOAD_ERR_PARTIAL:
                 $this->_uploadError = __d('file_storage', 'The uploaded file was only partially uploaded.');
                 return false;
             case UPLOAD_ERR_NO_FILE:
                 if ($options['allowNoFileError'] === false) {
                     $this->_uploadError = __d('file_storage', 'No file was uploaded.');
                     return false;
                 }
                 return true;
             case UPLOAD_ERR_NO_TMP_DIR:
                 $this->_uploadError = __d('file_storage', 'The remote server has no temporary folder for file uploads. Please contact the site admin.');
                 return false;
             case UPLOAD_ERR_CANT_WRITE:
                 $this->_uploadError = __d('file_storage', 'Failed to write file to disk. Please contact the site admin.');
                 return false;
             case UPLOAD_ERR_EXTENSION:
                 $this->_uploadError = __d('file_storage', 'File upload stopped by extension. Please contact the site admin.');
                 return false;
             default:
                 $this->_uploadError = __d('file_storage', 'Unknown File Error. Please contact the site admin.');
                 return false;
         }
         return false;
     }
     $this->_uploadError = '';
     return true;
 }