PHPackages                             yousefkadah/laravel-magika - 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. yousefkadah/laravel-magika

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

yousefkadah/laravel-magika
==========================

Laravel package for AI-powered file type validation using Google's Magika model

v1.0.0(3mo ago)30MITPHPPHP ^8.1

Since Apr 19Pushed 3mo agoCompare

[ Source](https://github.com/yousefkadah/magika)[ Packagist](https://packagist.org/packages/yousefkadah/laravel-magika)[ RSS](/packages/yousefkadah-laravel-magika/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (1)Dependencies (5)Versions (2)Used By (0)

 [![Laravel Magika](art/logo.svg)](art/logo.svg)

 [![Latest Version](https://camo.githubusercontent.com/cdacc1808be0f74a71d38af4dd003c596d42ae8288988f8da5692fbce50abf5d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f796f757365666b616461682f6c61726176656c2d6d6167696b612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/yousefkadah/laravel-magika) [![Total Downloads](https://camo.githubusercontent.com/cb7afc3b0610f626a5a935467cbd2da3e170ab6abdd7343204c3bcb166d51c69/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f796f757365666b616461682f6c61726176656c2d6d6167696b612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/yousefkadah/laravel-magika) [![License](https://camo.githubusercontent.com/278bdde788aea460e2826f79b145a61e18d2cf792880e4ac4b2c45e9de5d19d6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f796f757365666b616461682f6c61726176656c2d6d6167696b612e7376673f7374796c653d666c61742d737175617265)](https://github.com/yousefkadah/laravel-magika/blob/main/LICENSE)

---

AI-powered file type validation for Laravel using [Google's Magika](https://github.com/google/magika) — a deep learning model (~1 MB) that achieves ~99% accuracy across 200+ content types.

Unlike traditional MIME-type checking (which relies on file extensions or magic bytes), Magika uses a trained neural network to accurately identify file content, making it significantly harder to bypass with spoofed extensions or headers.

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

[](#requirements)

- PHP 8.1+
- Laravel 10, 11, or 12
- [Magika CLI](https://github.com/google/magika) installed on your system

### Installing the Magika CLI

[](#installing-the-magika-cli)

Choose one:

```
# macOS / Linux (Homebrew)
brew install magika

# Python (pipx)
pipx install magika

# Rust (Cargo)
cargo install --locked magika-cli
```

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

[](#installation)

```
composer require yousefkadah/laravel-magika
```

Publish the configuration (optional):

```
php artisan vendor:publish --tag=magika-config
```

Configuration
-------------

[](#configuration)

```
// config/magika.php
return [
    'binary_path'     => env('MAGIKA_BINARY_PATH', null),     // null = use system PATH
    'prediction_mode' => env('MAGIKA_PREDICTION_MODE', 'high-confidence'),
    'timeout'         => env('MAGIKA_TIMEOUT', 30),
];
```

Usage
-----

[](#usage)

### Detecting File Types

[](#detecting-file-types)

```
use YousefKadah\LaravelMagika\Facades\Magika;

// Detect a file by path
$result = Magika::detect('/path/to/file.pdf');

$result->label;       // "pdf"
$result->mimeType;    // "application/pdf"
$result->group;       // "document"
$result->description; // "PDF document"
$result->score;       // 0.99
$result->isText;      // false
$result->extensions;  // ["pdf"]

// Detect from raw content
$result = Magika::detectContent('
