awaisjameel/base64filehandler 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

awaisjameel/base64filehandler

最新稳定版本:1.0.0

Composer 安装命令:

composer require awaisjameel/base64filehandler

包简介

A Laravel package for handling and storing base64 encoded files.

README 文档

README

A Laravel package for handling and storing base64 encoded files.

Installation

You can install the package via composer:

composer require AwaisJameel/base64-file-handler

The package will automatically register its service provider if you're using Laravel 5.5+.

You can publish the configuration file with:

php artisan vendor:publish --provider="AwaisJameel\Base64FileHandler\Base64FileHandlerServiceProvider" --tag="config"

Configuration

After publishing the configuration file, you can find it at config/base64-file-handler.php. The configuration allows you to set:

  • Default storage disk
  • Default storage path
  • Allowed file extensions
  • Valid image extensions

Usage

Basic Usage

You can use the facade to store base64 encoded files:

use AwaisJameel\Base64FileHandler\Facades\Base64FileHandler;

// Store a base64 encoded file
$filePath = Base64FileHandler::store($base64Data);

// Store with custom parameters
$filePath = Base64FileHandler::store(
    $base64Data,
    'local',                   // custom disk
    'custom/path/',            // custom path
    'original-filename.jpg',   // original filename
    ['jpg', 'png']             // allowed extensions
);

Validating Images

use AwaisJameel\Base64FileHandler\Facades\Base64FileHandler;

try {
    Base64FileHandler::isValidImage($base64Data);
    // The data is a valid image
} catch (Exception $e) {
    // The data is not a valid image
}

Getting File Information

use AwaisJameel\Base64FileHandler\Facades\Base64FileHandler;

$fileInfo = Base64FileHandler::getFileInfo($base64Data);
// Returns array with mime, extension, size, and decoded data

Direct Instantiation

You can also use the class directly without the facade:

use AwaisJameel\Base64FileHandler\Base64FileHandler;

$handler = new Base64FileHandler([
    'disk' => 'local',
    'path' => 'custom/path/',
    'allowed_extensions' => ['jpg', 'png', 'pdf'],
]);

$filePath = $handler->store($base64Data);

Error Handling

The package throws exceptions when:

  • The base64 data is invalid
  • The file extension is not allowed
  • The image extension is invalid (when validating images)
  • Unable to store the file

Wrap your code in try-catch blocks to handle these exceptions.

Testing

composer test

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 15
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-02-28