Exemple #1
0
 /**
  * Checks if resource doesn't exceed provided size
  *
  * Please note that the size will always be checked against
  * limitations set in `php.ini` for `post_max_size` and `upload_max_filesize`
  * even if $max is set to false.
  *
  * @param Model $Model
  * @param array $field
  * @param mixed $max String (e.g. 8M) containing maximum allowed size, false allows any size
  * @return boolean
  */
 function checkSize(&$Model, $field, $max = false)
 {
     extract($this->runtime[$Model->alias]);
     foreach (array('source', 'temporary') as $type) {
         if ($type == 'temporary' && empty(${$type})) {
             continue;
         }
         if (!MediaValidation::size(${$type}['size'], $max)) {
             return false;
         }
     }
     return true;
 }
 function testSize()
 {
     $result = MediaValidation::size('1M', '2M');
     $this->assertTrue($result);
     $result = MediaValidation::size('1K', '2M');
     $this->assertTrue($result);
     $result = MediaValidation::size('1M', '1K');
     $this->assertFalse($result);
     $result = MediaValidation::size('1048576', '2M');
     $this->assertTrue($result);
     $result = MediaValidation::size(1048576, '2M');
     $this->assertTrue($result);
     $result = MediaValidation::size('1M', '1M');
     $this->assertTrue($result);
     $result = MediaValidation::size('1048576', '1M');
     $this->assertTrue($result);
     $result = MediaValidation::size(1048576, 10);
     $this->assertFalse($result);
     $result = MediaValidation::size('', '2M');
     $this->assertFalse($result);
 }