megoxv/laravel-magika
Composer 安装命令:
composer require megoxv/laravel-magika
包简介
A Laravel package for file type detection using Google Magika AI.
README 文档
README
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.
统计信息
- 总下载量: 269
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-19