Download the PHP package softcreatr/php-mime-detector without Composer

On this page you can find all versions of the php package softcreatr/php-mime-detector. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package php-mime-detector

PHP Mime Detector

A modern, extensible MIME type detector for PHP that analyses the actual bytes of a file instead of trusting its extension. The detector ships with a modular pipeline of signature matchers and a bidirectional repository of MIME type ↔ extension mappings so you can integrate it into security-sensitive workflows.

Features

Installation

Install the package via Composer:

Quick start

Detecting the MIME type and the preferred extension for a file is as simple as instantiating the façade and calling its helpers:

Resolving MIME types and extensions

The façade exposes several lookup helpers that do not require a file scan. They operate on the shared repository of known mappings:

Need a data URI? The detector will encode the configured file for you:

Optional ZipArchive support

The detector is fully functional without PHP's ZipArchive extension; all ZIP signatures are recognised by scanning the first 4 KiB of the file for well-known markers such as mimetype, [Content_Types].xml, or classes.dex. When the extension is present, the ZipSignatureDetector opens the archive and inspects its entries directly. This deeper look allows the detector to resolve format families like OOXML (.docx, .pptx, .xlsx), APK/JAR/XPI bundles, and other ZIP-based containers even when their identifying files live deeper inside the archive than the cached bytes.

If the extension is missing, the detector simply falls back to its heuristic path and ultimately reports a generic application/zip match whenever a more specific signature cannot be derived. Unit tests that require ZipArchive are skipped automatically when the class is not available, so no additional setup is needed to run the suite.

Extending the detector

Custom formats can be added without modifying the library itself. Choose the approach that fits your needs best.

Registering detectors via extensions

When you only need to extend the default pipeline, extensions are the quickest way to plug in extra detectors. The snippet below is a complete, copy & paste ready bootstrap that you can drop into a service provider, bootstrap.php, or any other file that runs before you instantiate the façade:

Extensions can be forgotten at runtime (MimeTypeDetector::forgetExtension('custom-container')) or reset entirely (MimeTypeDetector::flushExtensions()). Returning multiple detectors from an extension lets you register related matchers in one go while still benefiting from the priority-based ordering.

Building a custom pipeline

For more advanced scenarios you can compose a bespoke pipeline. Follow these steps to teach the detector about a new signature and MIME mapping.

1. Implement a signature detector

Create a class that implements SoftCreatR\MimeDetector\Contract\FileSignatureDetectorInterface. The detector receives the DetectionContext, which gives access to the file buffer and lets you return a MimeTypeMatch when the signature is recognised.

2. Register MIME mappings

Extend the repository so your MIME type resolves to the expected extension(s):

3. Compose (or customise) the detector pipeline

Most projects do not need to rebuild the pipeline manually. Once an extension is registered it is automatically merged with the default signature detectors in priority order:

If you do need full control you can still provide a bespoke pipeline. Simply prepend your detector to the default ones so it executes before the fallback signatures:

From this point the new MIME type behaves exactly like the built-in ones – it can be detected from files, resolved by MIME type, and listed in the catalogue.

Testing

Fixture files for the test suite are stored in a Git submodule. After cloning this repository run:

Contributing

We welcome pull requests! Please review CONTRIBUTING for the coding standards and workflow. When adding new detections, include at least one fixture so behaviour can be verified automatically.

License

Released under the ISC License.


All versions of php-mime-detector with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1.0
ext-ctype Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package softcreatr/php-mime-detector contains the following files

Loading the files please wait ...