Beispiel #1
0
 /**
  * @param \Zend_File_Transfer_Adapter_Http|\Zend_Validate $object
  * @param \Magento\Catalog\Model\Product\Option $option
  * @param array $fileFullPath
  * @return \Zend_File_Transfer_Adapter_Http|\Zend_Validate $object
  * @throws \Magento\Framework\Exception\InputException
  */
 protected function buildImageValidator($object, $option, $fileFullPath = null)
 {
     $dimensions = [];
     if ($option->getImageSizeX() > 0) {
         $dimensions['maxwidth'] = $option->getImageSizeX();
     }
     if ($option->getImageSizeY() > 0) {
         $dimensions['maxheight'] = $option->getImageSizeY();
     }
     if (count($dimensions) > 0) {
         if ($fileFullPath !== null && !$this->isImage($fileFullPath)) {
             throw new \Magento\Framework\Exception\InputException(__('File \'%1\' is not an image.', $option->getTitle()));
         }
         $object->addValidator(new \Zend_Validate_File_ImageSize($dimensions));
     }
     // File extension
     $allowed = $this->parseExtensionsString($option->getFileExtension());
     if ($allowed !== null) {
         $object->addValidator(new \Zend_Validate_File_Extension($allowed));
     } else {
         $forbidden = $this->parseExtensionsString($this->getConfigData('forbidden_extensions'));
         if ($forbidden !== null) {
             $object->addValidator(new \Zend_Validate_File_ExcludeExtension($forbidden));
         }
     }
     $object->addValidator(new \Zend_Validate_File_FilesSize(['max' => $this->fileSize->getMaxFileSize()]));
     return $object;
 }
Beispiel #2
0
 /**
  * Get max upload size
  *
  * @param string $configuredLimit
  * @return int
  */
 private function _getMaxUploadSize($configuredLimit)
 {
     $maxIniUploadSize = $this->_fileSize->getMaxFileSize();
     if ($configuredLimit === null) {
         return $maxIniUploadSize;
     }
     $maxUploadSize = $this->dataSize->convertSizeToBytes($configuredLimit);
     return min($maxUploadSize, $maxIniUploadSize);
 }
Beispiel #3
0
 /**
  * Get max upload size
  *
  * @param string $configuredLimit
  * @return int
  */
 private function _getMaxUploadSize($configuredLimit)
 {
     $maxIniUploadSize = $this->_fileSize->getMaxFileSize();
     if (is_null($configuredLimit)) {
         return $maxIniUploadSize;
     }
     $maxUploadSize = $this->_fileSize->convertSizeToInteger($configuredLimit);
     return min($maxUploadSize, $maxIniUploadSize);
 }
Beispiel #4
0
 /**
  * Get maximum file size to upload in bytes
  *
  * @return int
  */
 protected function _getFileMaxSize()
 {
     return $this->_fileConfig->getMaxFileSize();
 }
Beispiel #5
0
 /**
  * @backupStaticAttributes
  */
 public function testGetMaxFileSize()
 {
     $this->assertGreaterThanOrEqual(0, $this->_fileSize->getMaxFileSize());
     $this->assertGreaterThanOrEqual(0, $this->_fileSize->getMaxFileSizeInMb());
 }