jstewmc / validate-file-type
Validate a file's type
Installs: 6
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
pkg:composer/jstewmc/validate-file-type
Requires
- php: ^7.0
Requires (Dev)
- jstewmc/test-case: ^1.0
- mikey179/vfsstream: ^1.6
This package is auto-updated.
Last update: 2025-09-29 01:55:37 UTC
README
Validate a file's mime-type.
use Jstewmc\ValidateFileType\Validate; // create a txt file $txtFilename = '/path/to/foo.txt'; $txtContents = 'foo'; file_put_contents($txtFilename, $txtContents); // create an xml file $xmlFilename = '/path/to/foo.xml'; $xmlContents = '<?xml version="1.0" encoding="UTF-8"?><foo />'; file_put_contents($xmlFilename, $xmlContents); // create a service to validate text files $service = new Validate(['text/plain']); // validate our two files $service($txtFilename); // returns true $service($xmlFilename); // returns false
This library uses PHP's fileinfo extension to look for certain magic byte sequences in a file to guess it's type. While this is not a bulletproof approach, the heuristics used do a very good job.
That's it!
Author
License
Version
0.1.0, August 25, 2016
- Initial release