File Info
The FileInfoSampler
is a wrapper for the finfo
class. It requires the File Info Extension 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
command 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 documentation. 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 documentation. In addition, the follow resources may offer some help: