/** * Check maximum file size * * @param \Phalcon\Http\Request\File $file * @param mixed $value * @return bool */ public function checkMaxsize(\Phalcon\Http\Request\File $file, $value) { //conversion to the desired format if (is_array($value) === true) { $value = $value[key($value)]; } // check if ($file->getSize() > (int) $value) { $this->errors[] = sprintf(Message::get('INVALID_MAX_SIZE'), $file->getName(), Format::bytes($value)); return false; } return true; }
/** * Check if upload files are valid * * @return void */ public function move() { // do any actions if files exists foreach ($this->files as $n => $file) { $filename = $file->getName(); if (isset($this->rules['hash']) === true) { if (empty($this->rules['hash']) === true) { $this->rules['hash'] = 'md5'; } if (!is_string($this->rules['hash']) === true) { $filename = call_user_func($this->rules['hash']) . '.' . $file->getExtension(); } else { $filename = $this->rules['hash']($filename) . '.' . $file->getExtension(); } } if (isset($this->rules['sanitize']) === true) { $filename = Format::toLatin($filename, '', true); } if (isset($this->rules['directory'])) { $tmp = rtrim($this->rules['directory'], '/') . DIRECTORY_SEPARATOR . $filename; } else { $tmp = rtrim($this->rules['dynamic'], '/') . DIRECTORY_SEPARATOR . $filename; } // move file to target directory $isUploaded = $file->moveTo($tmp); if ($isUploaded === true) { $this->info[] = ['path' => $tmp, 'directory' => dirname($tmp), 'filename' => $filename, 'size' => $file->getSize(), 'extension' => $file->getExtension()]; } } return $this->getInfo(); }