检查上传的文件后缀是否合法
@param string $ext 后缀
@return bool
509444
private function checkExt($ext)
    {
        return empty($this->config['exts']) ? true : in_array(strtolower($ext), $this->exts);
    }
1279009
def has_extensions(self, *exts):
        """"""
        file_ext = splitext(self.filename)[1]
        file_ext = file_ext.lower()

        for e in exts:
            if file_ext == e:
                return True
        return False
299178
public function checkExt($ext)
    {
        if (strpos($ext, '.')) {
            $ext = pathinfo($ext, PATHINFO_EXTENSION);
        }
        if (strpos($this->allowedExts, $ext) === false) {
            return false;
        } else {
            return true;
        }
    }
1246789
public function acceptsMime($ext)
    {
        if ($this->getAllowedMimes() && !in_array($ext, $this->getAllowedMimes())) {
            return false;
        }

        if ($this->getRejectedMimes() && in_array($ext, $this->getRejectedMimes())) {
            return false;
        }

        return true;
    }
912941
public function change_ext($ext, $file){
    if ( !empty($ext) &&
      !empty($file) &&
      file_exists($file)
    ){
      $pi = pathinfo($file);
      $new = $pi['dirname'].'/'.$pi['filename'].'.'.$ext;
      bbn\file\dir::move($file, $new, true);
      return [
        'file' => $new,
        'file_url' => $this->real_to_url($new)
      ];
    }
    $this->error("Error.");
  }
956542
public static function get_app_category($ext)
    {
        $ext = strtolower($ext);
        foreach (static::config()->get('app_categories') as $category => $exts) {
            if (in_array($ext, $exts)) {
                return $category;
            }
        }
        return false;
    }
473383
public static function isRequired(common_ext_Extension $extension) {
        foreach (common_ext_ExtensionsManager::singleton()->getInstalledExtensions() as $ext) {
            foreach ($ext->getDependencies() as $extId => $version) {
                if ($extId == $extension->getId()) {
                    return true;
                }
            }
        }
        return false;
    }
1027356
protected function _compress($content, $ext) {
		$compress = $this->getConfig('compress');
		if ($compress === true) {
			// Native compressor only supports HTML right now
			if ($ext === 'html') {
				$Compressor = new Compressor();
				$content = $Compressor->compress($content);
			}
		} elseif (is_callable($compress)) {
			$content = $compress($content, $ext);
		} elseif ($compress) {
			$content = call_user_func($compress, $content, $ext);
		}

		return $content;
	}
1096145
public function downloadOnDemand($file, $ext = '')
    {
        // 1. 如果是/开头,认为是当前目录中的素材
        if ($file[0] == '/') {
            $file = ltrim($file, '/');

            return $file;
        }

        // 2. 下载文件到本地固定位置
        return $this->downloadIfRemote($file, $ext, md5($file));
    }
1212470
public function getFilesWithExtension($path, $ext = 'php')
    {
        if (is_dir($path)) {
            return new RegexIterator(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST, RecursiveIteratorIterator::CATCH_GET_CHILD // Ignore "Permission denied"
            ), '/^.+\.'.$ext.'$/i', RecursiveRegexIterator::GET_MATCH);
        } else {
            return [];
        }
    }
1194618
public static function _mime_types($ext = '')
    {
        $mimes = array(
            'hqx'   => 'application/mac-binhex40',
            'cpt'   => 'application/mac-compactpro',
            'doc'   => 'application/msword',
            'bin'   => 'application/macbinary',
            'dms'   => 'application/octet-stream',
            'lha'   => 'application/octet-stream',
            'lzh'   => 'application/octet-stream',
            'exe'   => 'application/octet-stream',
            'class' => 'application/octet-stream',
            'psd'   => 'application/octet-stream',
            'so'    => 'application/octet-stream',
            'sea'   => 'application/octet-stream',
            'dll'   => 'application/octet-stream',
            'oda'   => 'application/oda',
            'pdf'   => 'application/pdf',
            'ai'    => 'application/postscript',
            'eps'   => 'application/postscript',
            'ps'    => 'application/postscript',
            'smi'   => 'application/smil',
            'smil'  => 'application/smil',
            'mif'   => 'application/vnd.mif',
            'xls'   => 'application/vnd.ms-excel',
            'ppt'   => 'application/vnd.ms-powerpoint',
            'wbxml' => 'application/vnd.wap.wbxml',
            'wmlc'  => 'application/vnd.wap.wmlc',
            'dcr'   => 'application/x-director',
            'dir'   => 'application/x-director',
            'dxr'   => 'application/x-director',
            'dvi'   => 'application/x-dvi',
            'gtar'  => 'application/x-gtar',
            'php'   => 'application/x-httpd-php',
            'php4'  => 'application/x-httpd-php',
            'php3'  => 'application/x-httpd-php',
            'phtml' => 'application/x-httpd-php',
            'phps'  => 'application/x-httpd-php-source',
            'js'    => 'application/x-javascript',
            'swf'   => 'application/x-shockwave-flash',
            'sit'   => 'application/x-stuffit',
            'tar'   => 'application/x-tar',
            'tgz'   => 'application/x-tar',
            'xhtml' => 'application/xhtml+xml',
            'xht'   => 'application/xhtml+xml',
            'zip'   => 'application/zip',
            'mid'   => 'audio/midi',
            'midi'  => 'audio/midi',
            'mpga'  => 'audio/mpeg',
            'mp2'   => 'audio/mpeg',
            'mp3'   => 'audio/mpeg',
            'aif'   => 'audio/x-aiff',
            'aiff'  => 'audio/x-aiff',
            'aifc'  => 'audio/x-aiff',
            'ram'   => 'audio/x-pn-realaudio',
            'rm'    => 'audio/x-pn-realaudio',
            'rpm'   => 'audio/x-pn-realaudio-plugin',
            'ra'    => 'audio/x-realaudio',
            'rv'    => 'video/vnd.rn-realvideo',
            'wav'   => 'audio/x-wav',
            'bmp'   => 'image/bmp',
            'gif'   => 'image/gif',
            'jpeg'  => 'image/jpeg',
            'jpg'   => 'image/jpeg',
            'jpe'   => 'image/jpeg',
            'png'   => 'image/png',
            'tiff'  => 'image/tiff',
            'tif'   => 'image/tiff',
            'css'   => 'text/css',
            'html'  => 'text/html',
            'htm'   => 'text/html',
            'shtml' => 'text/html',
            'txt'   => 'text/plain',
            'text'  => 'text/plain',
            'log'   => 'text/plain',
            'rtx'   => 'text/richtext',
            'rtf'   => 'text/rtf',
            'xml'   => 'text/xml',
            'xsl'   => 'text/xml',
            'mpeg'  => 'video/mpeg',
            'mpg'   => 'video/mpeg',
            'mpe'   => 'video/mpeg',
            'qt'    => 'video/quicktime',
            'mov'   => 'video/quicktime',
            'avi'   => 'video/x-msvideo',
            'movie' => 'video/x-sgi-movie',
            'doc'   => 'application/msword',
            'word'  => 'application/msword',
            'xl'    => 'application/excel',
            'eml'   => 'message/rfc822',
        );
        return (!isset($mimes[strtolower($ext)])) ? 'application/octet-stream' : $mimes[strtolower($ext)];
    }
899675
public function acceptsMimeType($ext)
    {
        if ($this->getAllowedMimeTypes() && !in_array($ext, $this->getAllowedMimeTypes())) {
            return false;
        }

        if ($this->getRejectedMimeTypes() && in_array($ext, $this->getRejectedMimeTypes())) {
            return false;
        }

        return true;
    }
123721
public function findMimeType($ext = null) {
		if (empty($ext)) {
			return null;
		}
		return $this->find('all', ['conditions' => [$this->getAlias() . '.ext' => $ext]])->first();
	}
634323
public static File[] listFiles(final String ext) {
		init();
		
		return config.listFiles(new FilenameFilter() {

			public boolean accept(File dir, String name) {
				return name.endsWith(ext);
			}
		});
	}
671632
public function fileExt($ext) {
        $this->check_role = 'fileExt';
        if (is_string($ext)) {
            $ext = explode(',', $ext);
        }
        $this->rule = implode(',', $ext);
        if (!$this->value) {
            $result = false;
        } else if ($this->value instanceof File) {
            $result = in_array(strtolower($this->value->ext), $ext);
        } else {
            $x = explode(".", $this->value);
            $result = in_array(strtolower($x[ count($x) - 1 ]), $ext);
        }
        $this->checkResult($result);
    }
190578
protected function getDesiredImageQuality($ext, $format)
    {
        switch ($ext) {
            case 'jpeg':
            case 'jpg':
                $qualityConfig = $this->jpegQuality;
                break;

            case 'png':
                $qualityConfig = $this->pngQuality;
                break;

            default:
                $qualityConfig = null;
        }

        if (empty($qualityConfig)) {
            return null;
        }
        if (is_array($qualityConfig)) {
            if (isset($qualityConfig[$format])) {
                return $qualityConfig[$format];
            }
            if (isset($qualityConfig['default'])) {
                return $qualityConfig['default'];
            }
        }
        return $qualityConfig;
    }
1083643
def set_extension(self, ext):
        
        path = self._filename.split("/")
        parts = path[-1].split(".")
        if len(parts) == 1:
            parts.append(ext)
        else:
            parts[-1] = ext

        path[-1] = ".".join(parts)
        return File("/".join(path))