Get the extension of a file.

<p>Returns an empty string in case the file has no extension (or if no
file name was provided). The extension returned is always lowercase.</p>

@param string $file
@return string
497023
public static function getExtension($file){

		$file = trim($file);
		$extension = strtolower(substr(strrchr($file, '.'), 1));

		if($extension == $file){

			return '';
		}
		else{

			return $extension;
		}
	}
1141470
public function getModeByFile($file, $extension = null)
    {
        if (!$extension) {
            $extension = strtolower(substr($file, strrpos($file, '.')));
        }
        if (strpos($extension, '.') !== false) {
            if ($extension == '.csv') {
                return DATA_MANIPULATION_CREATE_MODE_CSV;
            }
            if ($extension == '.xls') {
                return DATA_MANIPULATION_CREATE_MODE_XLS;
            }
            if ($extension == '.xlsx') {
                return DATA_MANIPULATION_CREATE_MODE_XLSX;
            }
            if ($extension == '.ods') {
                return DATA_MANIPULATION_CREATE_MODE_ODS;
            }
        }
    }
835538
public function handle($file)
    {
        if (!$mime = $this->getMimeForEmit($file->getExtension())) {
            return $file;
        }
        if (!$file_loc = $file->getLocation()) {
            return $file;
        }
        $file->setMime($mime);
        $file->setFound();
        $fp   = fopen($file_loc, 'r');
        $file->setResource($fp);

        return $file;
    }
284782
public static String extension(String file) {
      if (StringUtils.isNullOrBlank(file)) {
         return StringUtils.EMPTY;
      }
      file = StringUtils.trim(file);
      int index = indexOfFileExtension(file);
      if (index == -1) {
         return StringUtils.EMPTY;
      }
      return file.substring(index + 1);
   }
1271482
protected function getMime($file)
    {
        $finfo = finfo_open(FILEINFO_MIME_TYPE);

        return finfo_file($finfo, $file->getRealPath() ?: $file->getPathname());
    }
1341111
public function generateExtension($file = null)
    {
        if ($file === null) {
            $file = $this->val();
        } elseif (is_string($file)) {
            if (in_array($file, $this->acceptedMimetypes())) {
                $mime = $file;
            } else {
                $mime = $this->mimetypeFor($file);
            }
        }

        return '';
    }
203613
protected function getExtensions($file)
    {
        $basename = strtolower(pathinfo($file, PATHINFO_BASENAME));

        // normalize
        foreach ($this->composedExtensions as $composedExtension => $canonicalExtension) {
            $basename = preg_replace('/\.'.preg_quote($composedExtension).'(\.|$)/', '.'.$canonicalExtension.'\\1', $basename);
        }

        $extensions = explode('.', $basename);
        $extensions = array_reverse(array_slice($extensions, 1));

        $recognizedExtensions = [];

        $i = 0;
        $extensionsNumber = count($extensions);

        while ($i < $extensionsNumber && array_key_exists($extensions[$i], $this->extensionMap)) {
            $recognizedExtensions[] = $extensions[$i];
            $i++;
        }

        return array_reverse($recognizedExtensions);
    }
1341065
private function findAvailableName($file)
    {
        $name = basename($file);

        if (!file_exists($this->directory.'/'.$name)) {
            return $name;
        }

        $dotPos = strrpos($name, '.');
        $prefix = substr($name, 0, $dotPos);
        $suffix = substr($name, $dotPos);

        $count = 1;
        do {
            $name = $prefix.'_'.$count.$suffix;
            $count++;
        } while (file_exists($this->directory.'/'.$name));

        return $name;
    }
510924
public static function getMimetype(string $file): string
    {
        $finfo = finfo_open(FILEINFO_MIME_TYPE); // return mime type ala mimetype extension
        $mimetype = finfo_file($finfo, $file);
        finfo_close($finfo);
        
        return $mimetype;
    }
754511
private function FileGetContents($file) {
    $fileObj = new SplFileObject($file, 'r');
    while (!$fileObj->flock(LOCK_EX)) {
      usleep(1);
    }
    $str = $fileObj->fread($fileObj->getSize());
    $fileObj->flock(LOCK_UN);
    return $str;
  }
510628
public function checkFilename($file)
    {
        $newFilename  = $file;
        $parts        = pathinfo($file);
        $origFilename = $parts['filename'];
        $ext          = (isset($parts['extension']) && ($parts['extension'] != '')) ? '.' . $parts['extension'] : null;

        $i = 1;

        while (file_exists($this->uploadDir . DIRECTORY_SEPARATOR . $newFilename)) {
            $newFilename = $origFilename . '_' . $i . $ext;
            $i++;
        }

        return $newFilename;
    }
932749
private function getRealFilename(string $file): string
    {
        if (strpos($file, 'vfs://') !== false) {
            return $file;
        }

        return $this->loader->getSourceContext($file)->getPath();
    }
1202644
public static function get_name($file, $ext = false) {
        $name = trim($file['name']);
        $name = str_replace(' ', '', $name);
        $name = str_replace('　', '', $name);
        if ($ext) {
            return $name;
        }
        $pos = strrpos($name, '.');
        if ($pos === false) {
            return $name;
        }
        return trim(substr($name, 0, $pos));
    }
217807
public function getFilePath($file): string
    {
        if (null === ($fileObj = $this->container->get('huh.utils.file')->getFileFromUuid($file))) {
            return '';
        }

        return $fileObj->path;
    }
710732
public static function extension($file, $separator = self::SEPARATOR_BOTH){
        return self::validate($file, $separator) ? substr($file, strrpos($file, '.') + 1) : false;
    }
1124116
public static String getExtension(File file)
    {
        Check.notNull(file);

        return getExtension(file.getName());
    }
922799
public static function getFile($file) {
		if(is_file($file)) {
			return $file;
		}
		$vendor = dirname(dirname(dirname(__FILE__)));
		$file   = '/'. ltrim($file, '/');
		if (is_file($vendor.$file)) {
			return $vendor.$file;
		}
		$app = dirname(APP_DIR);
		if (is_file($app.$file)) {
			return $app.$file;
		}
		return null;
	}