定制 hryvinskyi/magento2-media-uploader 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

hryvinskyi/magento2-media-uploader

最新稳定版本:1.0.0

Composer 安装命令:

composer require hryvinskyi/magento2-media-uploader

包简介

Media uploader module for Magento 2

README 文档

README

A Magento 2 module for handling media file uploads with support for temporary storage and permanent file management.

Installation

Via Composer

composer require hryvinskyi/module-media-uploader

Manual Installation

  1. Create directory app/code/Hryvinskyi/MediaUploader
  2. Copy module files to this directory
  3. Run setup commands:
bin/magento module:enable Hryvinskyi_MediaUploader
bin/magento setup:upgrade
bin/magento setup:di:compile

Configuration via DI Virtual Types

Configure file upload settings using virtual types in your module's di.xml:

<virtualType name="Your\Module\Model\FileUploader" type="Hryvinskyi\MediaUploader\Model\FileUploader">
    <arguments>
        <argument name="baseTmpPath" xsi:type="string">your_module/tmp/image</argument>
        <argument name="basePath" xsi:type="string">your_module/image</argument>
        <argument name="allowedExtensions" xsi:type="array">
            <item name="jpg" xsi:type="string">jpg</item>
            <item name="jpeg" xsi:type="string">jpeg</item>
            <item name="png" xsi:type="string">png</item>
            <item name="gif" xsi:type="string">gif</item>
            <item name="webp" xsi:type="string">webp</item>
        </argument>
        <argument name="allowedMimeTypes" xsi:type="array">
            <item name="jpg" xsi:type="string">image/jpg</item>
            <item name="jpeg" xsi:type="string">image/jpeg</item>
            <item name="png" xsi:type="string">image/png</item>
            <item name="gif" xsi:type="string">image/gif</item>
            <item name="webp" xsi:type="string">image/webp</item>
        </argument>
    </arguments>
</virtualType>

Usage Examples

Upload Command

use Hryvinskyi\MediaUploader\Api\Command\UploadInterface;

class YourController
{
    public function __construct(
        private readonly UploadInterface $uploadCommand
    ) {}

    public function execute(): array
    {
        // Upload file from $_FILES['image']
        return $this->uploadCommand->execute('image');
    }
}

Move File from Temporary Storage

use Hryvinskyi\MediaUploader\Api\Command\MoveFileFromTmpInterface;

class YourSaveController
{
    public function __construct(
        private readonly MoveFileFromTmpInterface $moveFileFromTmp
    ) {}

    public function execute(array $imageData): string
    {
        // Move file from tmp to permanent storage
        return $this->moveFileFromTmp->execute($imageData);
    }
}

Using FileUploader Directly

use Hryvinskyi\MediaUploader\Api\FileUploaderInterface;

class YourService
{
    public function __construct(
        private readonly FileUploaderInterface $fileUploader
    ) {}

    public function uploadAndMove(string $fileId): string
    {
        // Save to temporary directory
        $result = $this->fileUploader->saveFileToTmpDir($fileId);

        // Move to permanent storage
        return $this->fileUploader->moveFileFromTmp($result['name']);
    }
}

API Reference

FileUploaderInterface

Method Description
getBaseTmpPath(): string Get base temporary path for uploads
getBasePath(): string Get base path for permanent storage
getAllowedExtensions(): array Get list of allowed file extensions
getFilePath(string $path, string $imageName): string Build full file path
moveFileFromTmp(string $imageName): string Move file from tmp to permanent storage
saveFileToTmpDir(string $fileId): array Save uploaded file to temporary directory

UploadInterface

Method Description
execute(string $imageId = 'image'): array Execute file upload to temporary directory

MoveFileFromTmpInterface

Method Description
execute(array $image): string Move file from tmp and return relative path

Data Providers

PrepareImageToArray

Converts image path string to array format for UI components (used when loading data).

PrepareImageToString

Converts image array format to string path and moves file from tmp directory (used when saving data).

Requirements

  • PHP 8.1+
  • Magento 2.4.x
  • Magento_MediaStorage
  • Magento_Store

License

Proprietary

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: proprietary
  • 更新时间: 2026-01-31

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固