承接 atriatech/media 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

atriatech/media

Composer 安装命令:

composer require atriatech/media

包简介

Explore, Upload, Delete and Create new folder in your laravel project

README 文档

README

Media - Explore, Upload, Delete and Create new folder

Media - Explore, Upload, Delete and Create new folder

You can use this package to upload your media and attach the media to your models.

Version Laravel
^1.0.0 ^6.0.0
^2.0.0 ^8.0.0

Installation

  1. composer require atriatech/media.
  2. add Atriatech\Media\MediaServiceProvider::class to providers array inside config/app.php.
  3. add 'AtriatechMedia' => Atriatech\Media\Facades\AtriatechMedia::class to aliases array inside config/app.php.
  4. add "Atriatech\\Media\\": "vendor/atriatech/media/src/" to autoload => psr-4 object inside composer.json file, then run this command: composer dump-autoload.
  5. If you haven't link your storage, please run this command php artisan storage:link.
  6. run php artisan vendor:publish --tag=atriatech-media-config to copy the config file into config folder.
  7. run php artisan vendor:publish --tag=atriatech-media-public to copy asset files into public folder, running this command with --force flag is recommended.
  8. run php artisan vendor:publish --tag=atriatech-media-migrations to copy the migrations into database/migrations folder.
  9. run php artisan migrate to create the tables.

API

You can use these methods on your model:

Method Parameters Description Example
addMedia $paths - (Single-Array) Add media to your model User::findOrFail(1)->addMedia([$request->input('image')])
updateMedia $paths - (Array) Update media for your model User::findOrFail(1)->updateMedia([$request->input('image')])
removeMedia $name - (Single-Array) Remove media from your model User::findOrFail(1)->removeMedia('image')
getMedia - Return all the media for your model $media = User::findOrFail(1)->getMedia()
getMediaByName $pattern (String) Return all the media that has a name with the provided pattern $media = User::findOrFail(1)->getMediaByName('/(extra_images)/')
getMedium $id - (Integer) Get a single medium of your model with an id, If id is empty it will return the first medium $medium = User::findOrFail(1)->getMedium(2)
getMediumByName $name - (Single-Array) Get a single medium of your model with the name, If the name is empty it will return the first medium $medium = User::findOrFail(1)->getMediumByName('image')

There is a getSubSize method for a single medium which you can get a specific subSize (that you defined in the config file) of an image, using below code:

$medium->getSubSize('thumbnail');

Usage

First, take A look at the atriatech_media.php file in config folder.

Add AtriatechMedia to your model

use Atriatech\Media\AtriatechMedia;

class Product extends Model
{
    ...
    use AtriatechMedia;
    ...
}

In your view you have to load the css and js files and load the media selector:

Example:

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Atriatech Media</title>
    <!-- load the css file -->
    @atriatech_media('css')
</head>
<body>
<form method="post">
    @csrf
    <!-- load the media selector -->
    @atriatech_media_start
        @atriatech_media_file('img', '{"name": "image", "placeholder": "Image", "file": ""}')
    @atriatech_media_end
    <!-- load the media selector -->
    <br>
    <button type="submit">Submit</button>
</form>

<!-- load the js files -->
@atriatech_media('js')
</body>
</html>

The @atriatech_media_file directive has two parameters:

  1. ID - for the media selector
  2. OPTIONS - A JSON object with these keys:
{
    "name": "(String)", // the key which you can get in $request object when the form submitted
    "placeholder": "(String)", // placeholder for the media selector
    "file": "(String)", // Current media path to show in media selector
    "id": "(Number)" // Current media id
}

Upload from controller

To upload a file from controller simply use the AtriatechMedia facade.

use Atriatech\Media\Facades\AtriatechMedia;

class HomeController
{
    function index()
    {
        $file = $request->file('file');
        AtriatechMedia::upload($file, 'path'); // path is optional
    }
}

Load with JS

If you want to load the selector with javascript use the instruction below:

add this inside or outside the media selector blade directives.

@atriatech_media_start
<div id="mp3"></div>
@atriatech_media_end

<!-- OR -->

<div id="mp3"></div>

then load the selector with this code

AtriatechMedia.loadMediaSelectorWithJS('mp3', {name: 'mp3', placeholder: 'MP3', accept: '.mp3'});

The parameters of loadMediaSelectorWithJS method are exactly like @atriatech_media_file directive. It only has a third parameter that get true or false. you should pass false if you want to add that div element outside the media selector blade directives.

Integrations

CKEditor

In your view add a textarea:

<textarea name="editor1"></textarea>

Use media as CKEditor file browser:

CKEDITOR.replace( 'editor1', {
    filebrowserBrowseUrl: mediaRoute('atriatech.media.index'),
    filebrowserImageBrowseUrl: mediaRoute('atriatech.media.index') + '?accept={{ config('atriatech_media.mime_types.image/*') }}',
});

atriatech/media 适用场景与选型建议

atriatech/media 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 360 次下载、GitHub Stars 达 4, 最近一次更新时间为 2020 年 04 月 30 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「media」 「image」 「upload」 「resize」 「media-explorer」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 atriatech/media 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 atriatech/media 我们能提供哪些服务?
定制开发 / 二次开发

基于 atriatech/media 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 4
  • Watchers: 1
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-04-30