PHPackages                             jstewmc/validate-file-type - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. jstewmc/validate-file-type

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

jstewmc/validate-file-type
==========================

Validate a file's type

06PHP

Since Sep 6Pushed 9y ago1 watchersCompare

[ Source](https://github.com/jstewmc/validate-file-type)[ Packagist](https://packagist.org/packages/jstewmc/validate-file-type)[ RSS](/packages/jstewmc-validate-file-type/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependenciesVersions (1)Used By (0)

validate-file-type
==================

[](#validate-file-type)

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 = '';

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](http://php.net/manual/en/book.fileinfo.php) 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
------

[](#author)

[Jack Clayton](mailto:clayjs0@gmail.com)

License
-------

[](#license)

[MIT](https://github.com/jstewmc/validate-file-type/blob/master/LICENSE)

Version
-------

[](#version)

### 0.1.0, August 25, 2016

[](#010-august-25-2016)

- Initial release

###  Health Score

20

—

LowBetter than 13% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/50fecae0a7fd2119681bc133e496e7166b01a59f850a3c909e100bd427c6b28b?d=identicon)[Jstewmc](/maintainers/Jstewmc)

---

Top Contributors

[![jstewmc](https://avatars.githubusercontent.com/u/1192893?v=4)](https://github.com/jstewmc "jstewmc (3 commits)")

### Embed Badge

![Health badge](/badges/jstewmc-validate-file-type/health.svg)

```
[![Health](https://phpackages.com/badges/jstewmc-validate-file-type/health.svg)](https://phpackages.com/packages/jstewmc-validate-file-type)
```

###  Alternatives

[chaoswey/taiwan-id-validator

台灣身分證、統一編號驗證

319.9k](/packages/chaoswey-taiwan-id-validator)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
