承接 gravitypdf/upload 相关项目开发

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

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

gravitypdf/upload

Composer 安装命令:

composer require gravitypdf/upload

包简介

Handle file uploads with extensible validation and storage strategies

README 文档

README

codecov License: MIT

This component simplifies file validation and uploading.

Why was this library forked?

  • Original library was abandoned (untouched since 2018)
  • Adjusted namespace from \Upload to \GravityPdf\Upload
  • Bumped minimum PHP version to 7.3+
  • Sanitized filename and extension, and add UTF-8 filename support
  • Strict type checking
  • Added FileSystem::getDirectory() and FileInfo::setNameWithExtension() methods
  • Included unreleased code from upstream repo
  • PSR-12 Code Formatting
  • Automated tools: PHPUnit, PHPStan, PHPCS, and PHP Syntax Checker

TODO: PSR-7 and PSR-17 support (help wanted)

Installation

composer require gravitypdf/upload

Usage

Assume a file is uploaded with this HTML form:

<form method="POST" enctype="multipart/form-data">
    <input type="file" name="foo" value=""/>
    <input type="submit" value="Upload File"/>
</form>

When the HTML form is submitted, the server-side PHP code can validate and upload the file like this:

$storage = new \GravityPdf\Upload\Storage\FileSystem('/path/to/directory');
// To override existing files when uploading, pass `true` as the second parameter
// $storage = new \GravityPdf\Upload\Storage\FileSystem('/path/to/directory', true);
$file = new \GravityPdf\Upload\File('foo', $storage);

// Validate file upload
// MimeType List => http://www.iana.org/assignments/media-types/media-types.xhtml
$file->addValidations([
    // Ensure file is of type "image/png"
    new \GravityPdf\Upload\Validation\Mimetype('image/png'),
    new \GravityPdf\Upload\Validation\Extension('png'),

    //You can also add multi mimetype validation or extensions
    //new \GravityPdf\Upload\Validation\Mimetype(['image/png', 'image/gif'])
    //new \GravityPdf\Upload\Validation\Extension(['png', 'gif']),

    // Ensure file is no larger than 5M (use "B", "K", M", or "G")
    new \GravityPdf\Upload\Validation\Size('5M'),
]);

// Access data about the file
// If upload accepts multiple files an array will be returned for each of these
$data = [
    'name' => $file->getNameWithExtension(),
    'extension' => $file->getExtension(),
    'mime' => $file->getMimetype(),
    'size' => $file->getSize(),
    'md5' => $file->getMd5(),
    'dimensions' => $file->getDimensions(),
];

// If you have an upload field that accepts multiple files you can access each file's info individually
$firstFileName = $file[0]->getNameWithExtension();
if(isset($file[1])) {
    $secondFileName = $file[1]->getNameWithExtension();
}

// or loop over all files for this key
foreach($file as $i => $upload) {
    $name = $upload->getNameWithExtension();
    $upload->setName('file-'.$i);
}

// Try to upload file(s)
try {
    // Success!
    $file->upload();
} catch (\Exception $e) {
    // Validation errors
    $errors = $file->getErrors();
    if(count($errors) === 0) {
        // Failed for another reason, like the file already exists
        $error = $e->getMessage();
    }
}

Authors

License

MIT Public License

gravitypdf/upload 适用场景与选型建议

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

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-07-06