megoxv/laravel-magika

A Laravel package for file type detection using Google Magika AI.

Maintainers

Package info

github.com/megoxv/laravel-magika

pkg:composer/megoxv/laravel-magika

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-04-19 10:47 UTC

This package is auto-updated.

Last update: 2026-04-19 10:52:17 UTC


README

Latest Version on Packagist Total Downloads License

Laravel Magika AI is a high-performance file type detection package for Laravel. It utilizes Google's Magika deep learning model to accurately identify file types based on their content rather than extensions.

Key Features

  • AI-Powered: Uses Google's deep learning model (Magika) for 99%+ accuracy.
  • Fast and Lightweight: Inference takes only a few milliseconds per file.
  • Support for 100+ Formats: Accurately detects code, documents, archives, and media.
  • Security Focused: Detects misleading extensions (e.g., PHP code disguised as a JPG).
  • Confidence Scoring: Require a minimum AI confidence score before accepting uploads.

Installation

Install the package via composer:

composer require megoxv/laravel-magika

Download and install the appropriate Magika binary for your system:

php artisan magika:install

Check the installation status anytime:

php artisan magika:install --status

Usage

Validation Rule

Use the magika rule in your controllers. You can specify allowed labels and an optional minimum confidence score.

// Simple usage (allow only PDF)
$request->validate([
    'document' => 'required|file|magika:pdf'
]);

// With Confidence Threshold (e.g., must be 95% sure it's a PDF)
$request->validate([
    'document' => 'required|file|magika:pdf,0.95'
]);

// Multiple types
$request->validate([
    'profile_image' => 'required|file|magika:png,jpeg,0.9'
]);

Using the Facade

use Megoxv\LaravelMagika\Facades\Magika;

$result = Magika::predict($path);

echo $result->label;      // e.g., "pdf"
echo $result->mimeType;   // e.g., "application/pdf"
echo $result->score;      // e.g., 0.992
echo $result->isText;     // true/false

Using the Helper

$result = magika()->predict($path);

Configuration

Publish the config file:

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

License

The MIT License; see LICENSE for details.