示例#1
0
 /**
  * 验证上传文件的类型是否为图片及大小是否越界
  * @param $file
  * @param int $max_file_size
  * @return bool|string
  */
 public static function validateUpload($file, $max_file_size = 0)
 {
     if ((int) $max_file_size > 0 && $file['size'] > (int) $max_file_size) {
         return sprintf(Tools_help::displayError('Image is too large (%1$d kB). Maximum allowed: %2$d kB'), $file['size'] / 1024, $max_file_size / 1024);
     }
     if (!Files_ImageManager::isRealImage($file['tmp_name'], $file['type']) || !Files_ImageManager::isCorrectImageFileExt($file['name'])) {
         return 'Image format not recognized, allowed formats are: .gif, .jpg, .png';
     }
     if ($file['error']) {
         return sprintf(Tools_help::displayError('Error while uploading image; please change your server\'s settings. (Error code: %s)'), $file['error']);
     }
     return true;
 }