File Info

The FileInfoSampler is a wrapper for the finfo classopen in new window. It requires the File Info Extensionopen in new window to be installed.

Options

FileInfoSampler offers the following options, which can be specified in your "profile" settings.

If you are using package in a regular Laravel application, then you can change options in your config/mime-types-detection.php file.

use Aedart\MimeTypes\Detector;
use Aedart\MimeTypes\Drivers\FileInfoSampler;

$detector = new Detector([
    'default' => [
        'driver' => FileInfoSampler::class,
        'options' => [
            // Amount of bytes to sample from file
            'sample_size' => 1048576,
            
            // Path to custom magic database
            'magic_database' => null,
        ]
    ],
]);

sample_size

The sample size determines how many bytes from a file's content must be used for determining the MIME-type. The default value of 1048576 bytes (~1 MB) corresponds to the default size of the linux file commandopen in new window uses.

Feel free to tinker with this size as you see fit. For instance, during the development of this package a much smaller value (512 bytes) was used during testing. All test-files' MIME-type were detected as expected. Yet, depending on the files that you attempt to detect MIME-types for, no guarantees can be provided. In other words, you should test against desired files to see what sample size works.

magic_database

The default value of null works in the same way as specified by the File Extension documentationopen in new window. In other words, you are encouraged to just leave it unset.

If you do wish to use a custom magic database, then you should look at the file command documentationopen in new window. In addition, the follow resources may offer some help: