定制 intervention/mimesniffer 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

intervention/mimesniffer

最新稳定版本:2.1.0

Composer 安装命令:

composer require intervention/mimesniffer

包简介

PHP MIME Type Sniffer

README 文档

README

Latest Version Tests Monthly Downloads Support me on Ko-fi

Detecting MIME Content-type in PHP is easy with mime_content_type or Fileinfo. But Fileinfo as an extension is sometimes not available on the server. The function mime_content_type wants a path to the filesystem as argument and doesn't process if we only have a string value. This package makes it easy to detect the mime types of the content of a given file or string, without any extension dependencies.

Installation

Install the package easily via composer:

composer require intervention/mimesniffer

Usage

Here are some code samples, to show how the library is handled.

use Intervention\MimeSniffer\MimeSniffer; use Intervention\MimeSniffer\Types\ImageJpeg; // universal factory method $sniffer = MimeSniffer::create($content); // or detect given string $sniffer = MimeSniffer::createFromString($content); // or detect given file $sniffer = MimeSniffer::createFromFilename('image.jpg'); // or detect from file pointer $sniffer = MimeSniffer::createFromFilename(fopen('test.jpg', 'r')); // returns object of detected type  $type = $sniffer->getType(); $bool = $type->isBinary(); // check if we have binary data $bool = $type->isImage(); // check if we are dealing with an image $bool = $type->isVideo(); // check video data was detected $bool = $type->isAudio(); // check if we have detected audio data $bool = $type->isArchive(); // check if an archive was detected $type = (string) $type; // cast type to string (e.g. "image/jpeg") // you can also check, if the content matches a specific type $bool = $sniffer->matches(new ImageJpeg); // or check, if the content matches an array of types $bool = $sniffer->matches([ImageJpeg::class, ImageGif::class]); // or check, if the content matches an array of type objects $bool = $sniffer->matches([new ImageJpeg, $type]);

If your prefer non-static initialization:

use Intervention\MimeSniffer\MimeSniffer; // create instance with constructor $sniffer = new MimeSniffer($content); // with setter for given content $type = $sniffer->setFromString($other_content)->getType(); // or with setter for filename $type = $sniffer->setFromFilename('images/image.jpg')->getType(); // or with setter for file pointer $type = $sniffer->setFromPointer(fopen('images/image.jpg', 'r'))->getType();

Currently only the following file types can be detected. More will be added in a next release.

Images

  • Image encoded as JPEG raw or in the JFIF or Exif file format
  • Image file encoded in the Graphics Interchange Format (GIF)
  • Image encoded in the Portable Network Graphics format (PNG)
  • Image encoded as BMP file, a bitmap format
  • Image encoded in High Efficiency Image File Format (HEIC/HEIF)
  • Icon encoded in ICO file format
  • Image in Google WebP image format
  • Scalable Vector Graphics (SVG)
  • Tagged Image File Format (TIFF)
  • Image encoded Photoshop Document file format (PSD)
  • AV1 Image File Format (AVIF)
  • JPEG 2000 File Format

Archives

  • GZIP compressed
  • ZIP file
  • RAR archive
  • TAR file

Videos

  • AVI
  • MPEG-1 and MPEG-2 video
  • MKV media container

Audio

  • MP3 file
  • FLAC file

Other

  • PDF document
  • OGG media container
  • SQLite Database
  • application/octet-stream (default binary)
  • text/plain (default)

Contributing

Contributions are welcome. Please note the following guidelines before submiting your pull request.

  • Follow PSR-2 coding standards.
  • Write tests for new functions and added features

Development & Testing

With this package comes a Docker image to build a test suite and analysis container. To build this container you have to have Docker installed on your system. You can run all tests with this command.

docker-compose run --rm --build tests

Run the static analyzer on the code base.

docker-compose run --rm --build analysis

Authors

This library is developed and maintained by Oliver Vogel

License

Intervention MimeSniffer is licensed under the MIT License.

统计信息

  • 总下载量: 307.99k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 23
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 23
  • Watchers: 1
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固