ここの情報は古いです。ご理解頂いた上でお取り扱いください。

Changeset 11052


Ignore:
Timestamp:
Mar 18, 2009, 5:33:11 PM (11 years ago)
Author:
ShogoKawahara
Message:

fixed opValidatorImageFile doesn't limit file size correctly

File:
1 edited

Legend:

Unmodified
Added
Removed
  • OpenPNE3/trunk/lib/validator/opValidatorImageFile.class.php

    r11021 r11052  
    2222    parent::configure($options, $messages);
    2323    $this->setOption('mime_types', 'web_images');
    24     $this->setOption('max_size', opConfig::get('image_max_filesize'));
     24
     25    $maxFilesize = opConfig::get('image_max_filesize');
     26    switch (strtoupper(substr($maxFilesize, -1)))
     27    {
     28      case 'K' :
     29        $maxFilesize = (int)$maxFilesize * 1024;
     30        break;
     31      case 'M' :
     32        $maxFilesize = (int)$maxFilesize * 1024 * 1024;
     33        break;
     34    }
     35   
     36    $this->setOption('max_size', (int)$maxFilesize);
     37  }
     38
     39  protected function doClean($value)
     40  {
     41    try
     42    {
     43      return parent::doClean($value);
     44    }
     45    catch (sfValidatorError $e)
     46    {
     47      if ($e->getCode() == 'max_size')
     48      {
     49        $arguments = $e->getArguments(true);
     50        throw new sfValidatorError($this, 'max_size', array('max_size' => opConfig::get('image_max_filesize'), 'size' => $arguments['size']));
     51      }
     52      throw $e;
     53    }
    2554  }
    2655}
Note: See TracChangeset for help on using the changeset viewer.