2017 © Pedro Peláez
 

library validate-file-type

Validate a file's type

image

jstewmc/validate-file-type

Validate a file's type

  • Tuesday, September 6, 2016
  • by Jstewmc
  • Repository
  • 1 Watchers
  • 0 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

validate-file-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)

Author

Jack Clayton, (*4)

License

MIT, (*5)

Version

0.1.0, August 25, 2016

  • Initial release

The Versions

06/09 2016

dev-master

9999999-dev

Validate a file's type

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

by Jack Clayton

file php validate type jstewmc