定制 sudippalash/mediauploader 二次开发

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

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

sudippalash/mediauploader

Composer 安装命令:

composer require sudippalash/mediauploader

包简介

Laravel package for Media Uploader

README 文档

README

Latest Version on Packagist Total Downloads

mediauploader is a simple file-handling package for Laravel that provides various options for managing files, including image uploads, file uploads, WebP uploads, base64 image uploads, image uploads from URLs, and Google image content uploads. The package currently supports public, local, and s3 storage (note: only publicly accessible S3 buckets are supported).

It also includes file and image preview functionality.

Install

Via Composer

composer require sudippalash/mediauploader

Publish config file

You should publish the config file with:

php artisan vendor:publish --provider="Sudip\MediaUploader\Providers\AppServiceProvider" --tag=config

In config/mediauploader.php config file you should set mediauploader global path.

return [
    /*
    |--------------------------------------------------------------------------
    | Base Directory
    |--------------------------------------------------------------------------
    |
    | base_dir stores all other directory inside storage folder of your laravel application by default
    | if you specify any name. all storage will be done inside that directory or name that you specified
    |
    */

    'base_dir' => null,

    /*
    |--------------------------------------------------------------------------
    | Thumb Directory
    |--------------------------------------------------------------------------
    |
    | thumb_dir creates another folder inside the directory as a "thumb" by default
    | you can change the name thumb to any other name you like.
    */

    'thumb_dir' => 'thumb',

    /*
    |--------------------------------------------------------------------------
    | Timestamp Prefix
    |--------------------------------------------------------------------------
    |
    | If timestamp_prefix is true then create a file with a timestamp to ignore the same name image replacement. Example: image-1658562981.png.
    | If timestamp_prefix is false then the script checks file exists or not if the file exists then add the time() prefix for the new file otherwise leave it as the file
    | name.
    */

    'timestamp_prefix' => false,

    /*
    |--------------------------------------------------------------------------
    | Thumb Image Height Width
    |--------------------------------------------------------------------------
    |
    | specify the thumb image ratio of height and weight by default it takes 300px X 300px
    */

    'image_thumb_height' => 300,
    'image_thumb_width' => 300,

    /*
    |--------------------------------------------------------------------------
    | Fake Image Url
    |--------------------------------------------------------------------------
    |
    | fake_image_url , if you specify a fake image path or url here. the entire package will use
    | this image when there is no image found. or you can specify the fake image in the
    | function parameter as well.
    | Example: 'fake_image_url' => 'images/fake.png' or 'fake_image_url' => 'https://example.com/images/fake.png,
    */

    'fake_image_url' => null,

    /*
    |--------------------------------------------------------------------------
    | Folder permission
    |--------------------------------------------------------------------------
    |
    | path_permission , if you create a folder in your project then you can define your folder permission.
    | Example: null, 0755, 0777
    */

    'path_permission' => 0777,
];

Configuration

Before using this, you must complete the following steps (if you want to use the default filesystem disk, which is public):

  1. Change your env filesystem drive to this if you want to use public storage directory.
FILESYSTEM_DISK=public
  1. Please make sure to link your storage before using this package
php artisan storage:link
  1. You can also specify the filesystem disk when using image or file functions (see the usage section for details).
MediaUploader::disk('local')->usageFunction();

Usage (File Upload)

  1. Image Upload
MediaUploader::imageUpload(<UploadedFile image>, <output path>, thumb=false, name=null, $imageResize = [], $thumbResize = [0, 0]);

Example:

$file = MediaUploader::imageUpload($request->file, 'images', 1, null, [600, 600]);

if ($file) {
    // File is saved successfully
}
  1. Webp Image Upload
MediaUploader::webpUpload(<UploadedFile image>, <output path>, thumb=false, name=null, $imageResize = [], $thumbResize = [0, 0]);

Example:

$file = MediaUploader::webpUpload($request->file, 'webps', 1, null, [600, 600]);

if ($file) {
    // File is saved successfully
}
  1. Any Upload (if you are not sure what type of file is, you can use this)
MediaUploader::anyUpload(<UploadedFile file>, <output path>, name=null);

Example:

$file = MediaUploader::anyUpload($request->file, 'files', 'filename');

if ($file) {
    // File is saved successfully
}
  1. Image Upload from URL
MediaUploader::imageUploadFromUrl(<Valid Image URL>, <output path>, thumb=false, name=null, $imageResize = [], $thumbResize = [0, 0]);

Example:

$file = MediaUploader::imageUploadFromUrl($url, 'images', 1, null, [600, 600]);

if ($file) {
    // File is saved successfully
}
  1. Base64 image Upload
MediaUploader::base64ImageUpload(<base64 Content>, <output path>, thumb=false, name=null, $imageResize = [], $thumbResize = [0, 0]);

Example:

$file = MediaUploader::base64ImageUpload($content, 'images', 1, null, [600, 600]);

if ($file) {
    // File is saved successfully
}
  1. Content Upload
MediaUploader::contentUpload(<Content>, <output path>, name=null);

Example:

$file = MediaUploader::contentUpload($content, 'contents', 'name');

if ($file) {
    // File is saved successfully
}
  1. Thumb (to create a thumb from an existing image, you can use this)
MediaUploader::thumb(<output path>, <file>, $thumbPath = false, $thumbWidth = 0, $thumbHeight = 0);

Example:

$file = MediaUploader::thumb('thumbs', $file, 200, 200);

if ($file) {
    // File is saved successfully
}

Returns:

Response from every function looks like this

[
    "name" => "example-image.jpg"
    "originalName" => "example-image.jpg"
    "size" => 148892
    "width" => 600
    "height" => 600
    "mime_type" => "image/jpeg"
    "ext" => "jpg"
    "url" => "http://localhost/storage/test/example-image.jpg"
]

Usage (File Delete)

File Delete

MediaUploader::delete(<path>, <file_name>, $thumb = false)

Example:

$file = MediaUploader::delete('images', $file_name, true);

if ($file) {
    // File is deleted successfully
}

Usage (Directory Delete)

Directory Delete

MediaUploader::removeDirectory(<path>)

Example:

$path = MediaUploader::removeDirectory('images');

if ($path) {
    // Directory is deleted successfully
}

Usage (FIle or Image Exists check)

  1. FIle/Image Exists
MediaUploader::fileExists(<path>, <file_name>)

Example:

if(MediaUploader::fileExists('images', $file_name)) {
    // 
}

Usage (FIle or Image URL & Preview)

  1. FIle or Image Url
MediaUploader::showUrl(<path>, <file_name>)

Example:

{!! MediaUploader::showUrl('images', $file_name) !!}
  1. File Preview
MediaUploader::showFile(<path>, <file_name>, <file_not_found_text|optional>)

Example:

{!! MediaUploader::showFile('images', $file_name, $empty_text) !!}
  1. File Preview from url
MediaUploader::showFileFromUrl(<url>, <file_name|optional>, <file_not_found_text|optional>)

Example:

{!! MediaUploader::showFileFromUrl($file_url, $file_name, $empty_text) !!}
  1. Image Preview
MediaUploader::showImg(<path_or_url>, <file_name>, <array options>)

Example:

{!! MediaUploader::showImg($pathOrUrl, $file_name, [
    'thumb' => true, // If thumb image store via upload function.
    'popup' => true, // Currently support only jQuery fancybox.
    'fakeImg' => 'images/avatar.png', // Pass fake image path without url or pass true (if pass true it will generate fake image from config file fake_image_url value).
    'id' => 'image',
    'class' => 'img-fluid',
    'style' => '',
    'alt' => 'Nice Image',
]) !!}

sudippalash/mediauploader 适用场景与选型建议

sudippalash/mediauploader 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.08k 次下载、GitHub Stars 达 5, 最近一次更新时间为 2021 年 12 月 07 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 5
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-12-07