PHPackages                             rafalimanana/file-validator - 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. rafalimanana/file-validator

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

rafalimanana/file-validator
===========================

Validation de fichier

0.0.6(2y ago)015MITPHPPHP &gt;=8.0

Since Aug 18Pushed 2y ago1 watchersCompare

[ Source](https://github.com/rafalimanana/validation_file)[ Packagist](https://packagist.org/packages/rafalimanana/file-validator)[ RSS](/packages/rafalimanana-file-validator/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (6)Used By (0)

file-validator
==============

[](#file-validator)

Requirements
------------

[](#requirements)

- PHP version 8.0 ou supérieure

Installation
------------

[](#installation)

- Avec composer:

```
composer require rafalimanana/file-validator

```

- Avec composer.phar:

```
php composer.phar require rafalimanana/file-validator

```

Utilisation
-----------

[](#utilisation)

### FileValidator

[](#filevalidator)

#### Importation de la classe

[](#importation-de-la-classe)

```
use Pw\FileValidator\FileValidator
```

#### Instanciation

[](#instanciation)

```
$fileValidator = new FileValidator([]);
```

#### Exemple d’utilisation

[](#exemple-dutilisation)

###### Utilisation avec les définitions des extensions, des types et de la taille des fichiers autorisés

[](#utilisation-avec-les-définitions-des-extensions-des-types-et-de-la-taille-des-fichiers-autorisés)

```
use Pw\FileValidator\FileValidator

$allowedMimeTypes = ['image/jpeg', 'image/png'];
$allowedExtensions = ['jpg', 'jpeg', 'png'];
$maxFileSize = 1024 * 1024; // 1 MB

$fileValidator = new FileValidator(
    $allowedMimeTypes,
    $allowedExtensions,
    $maxFileSize
);

$file = [
    'name' => 'example.jpg',
    'type' => 'image/jpeg',
    'size' => 500000, // 500 KB
];

if ($fileValidator->validateFile($file)) {
    //Le fichier est valide.
} else {
    //Le fichier n'est pas valide.
}
```

###### Utilisation de verifier le type de fichier comme `image` en appelant juste la méthode `isImage`.

[](#utilisation-de-verifier-le-type-de-fichier-comme-image-en-appelant-juste-la-méthode-isimage)

```
use Pw\FileValidator\FileValidator

$fileValidator = new FileValidator();

$mimetype = $file->getMimeType();//Type de fichier

if ($fileValidator->isImage($mimetype)) {
    //Le fichier est un image.
} else {
    //Le fichier n'est un image.
}

//ou
if ($fileValidator->isImage($file)) {//Objet de fichier
    //Le fichier est un image.
} else {
    //Le fichier n'est un image.
}
```

###### Quelques méthodes sur la validation de fichier.

[](#quelques-méthodes-sur-la-validation-de-fichier)

```
uploadToPath($file, $dir, $file_name)
isImage($file)
isPdf($file)
isDocx($file)
isExcel($file)
isVideo($file)
getFileType($file)
validSize($file, $max_mb=1)
validateMimeType($file)
validateExtension($file)
validateFile($file)
```

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity42

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.

###  Release Activity

Cadence

Every ~1 days

Total

5

Last Release

992d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d657e7a99a7a6e982699b8842db4c2847ec2f9dc5d05733a8bb5a4f2b8be7527?d=identicon)[rafalimanana](/maintainers/rafalimanana)

---

Top Contributors

[![rafalimanana](https://avatars.githubusercontent.com/u/21891806?v=4)](https://github.com/rafalimanana "rafalimanana (8 commits)")

### Embed Badge

![Health badge](/badges/rafalimanana-file-validator/health.svg)

```
[![Health](https://phpackages.com/badges/rafalimanana-file-validator/health.svg)](https://phpackages.com/packages/rafalimanana-file-validator)
```

###  Alternatives

[webmozart/assert

Assertions to validate method input/output with nice error messages.

7.6k894.0M1.2k](/packages/webmozart-assert)[bensampo/laravel-enum

Simple, extensible and powerful enumeration implementation for Laravel.

2.0k15.9M104](/packages/bensampo-laravel-enum)[swaggest/json-schema

High definition PHP structures with JSON-schema based validation

48612.5M73](/packages/swaggest-json-schema)[stevebauman/purify

An HTML Purifier / Sanitizer for Laravel

5325.6M19](/packages/stevebauman-purify)[ashallendesign/laravel-config-validator

A package for validating your Laravel app's config.

217905.3k5](/packages/ashallendesign-laravel-config-validator)[crazybooot/base64-validation

Laravel validators for base64 encoded files

1341.9M8](/packages/crazybooot-base64-validation)

PHPackages © 2026

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