dev-master
9999999-devValidate a file's type
MIT
The Requires
- php ^7.0
The Development Requires
- jstewmc/test-case ^1.0
- mikey179/vfsstream ^1.6
by Jack Clayton
file php validate type jstewmc
Wallogit.com
2017 © Pedro Peláez
Validate a file's type
Validate a file's mime-type., (*1)
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 = '<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., (*2)
That's it!, (*3)
Jack Clayton, (*4)
MIT, (*5)
Validate a file's type
MIT
file php validate type jstewmc