示例#1
0
 /**
  * Pass only images with dimension size between given values.
  * Caution, action performs at the calling time.
  *
  * @param int max image width
  * @param int max image height
  * @param int min image width
  * @param int min image height
  * @return UploadedFiles object
  * @see allowedSize
  */
 function allowedImageSize($max_width = 800, $max_height = 600, $min_width = 0, $min_height = 0)
 {
     if (!isset($min_height, $max_height, $min_width, $max_width)) {
         return;
     }
     $min_height = abs($min_height);
     $max_height = abs($max_height);
     $min_width = abs($min_width);
     $max_width = abs($max_width);
     if ($max_height - $min_height <= 0) {
         return $this;
     }
     if ($max_width - $min_width <= 0) {
         return $this;
     }
     foreach ($this->http_files as $k => $v) {
         $mime = isset($this->cached_mimes[$k]) ? $this->cached_mimes[$k] : ($this->cached_mimes[$k] = getMime($v['tmp_name']));
         if (($pos = strpos($mime, "image")) !== false && $pos == 0) {
             $s = getImgSizeNoCache($v['tmp_name']);
             if ($min_height && $s['height'] < $min_height) {
                 $this->http_error_files[$k][] = array('min_height', $v['name'], $min_height, $s['height']);
             } elseif ($max_height && $s['height'] > $max_height) {
                 $this->http_error_files[$k][] = array('max_height', $v['name'], $max_height, $s['height']);
             }
             if ($min_width && $s['width'] < $min_width) {
                 $this->http_error_files[$k][] = array('min_width', $v['name'], $min_height, $s['width']);
             } elseif ($max_width && $s['width'] > $max_width) {
                 $this->http_error_files[$k][] = array('max_width', $v['name'], $max_height, $s['width']);
             }
         }
     }
     return $this;
 }
示例#2
0
function getImgSize($path = null)
{
    if (Config::get("USE_IMAGES_CACHE")) {
        return getImgSizeCache($path);
    } else {
        return getImgSizeNoCache($path);
    }
}