/** * 获取文件名称 * @param string $filePath * @return string */ public static function getFileName($filePath) { $pos = strrpos($filePath, '/'); if ($pos === false) { return $filePath; } else { return substr($filePath, $pos + 1); } } /** * 获取文件扩展名 * @param string $filePath * @param string $default 默认文件名 * @return string */ public static function getFileExt($filePath, $default = 'jpg') { $fileName = self::getFileName($filePath); //获取可能出现的 $pos = strrpos($fileName, '.'); if ($pos === false) { return $default; } else { return substr($fileName, $pos + 1); } }